Android: java.lang.IllegalMonitorStateException: object is not locked by thread before waiting ()

I have this Android code that is stuck in a synchronized application. Even if I delete process1.wait (), I will catch exception.any help is appreciated?

 private class LongOperation extends AsyncTask<String, Void, String>
   {

      @Override
      protected String doInBackground(String... params)
      {
         try
         {
     Process process1 = new ProcessBuilder("sh", "/data/local/bin/tcpdump.sh").start();            
            synchronized(process1){
               process1.wait();
             }
         }
         catch (Exception e)
         {
            Log.e("Tcpdump function error", "Unable to capture the packets into the buffer");
         }
         return null;
      }

      /* (non-Javadoc)
       * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
       */
      @Override
      protected void onPostExecute(String result)
      {
         try
         {  
            StringBuffer output = new StringBuffer();
            File file = new File("/data/local/bin/dump.txt");
            BufferedReader br = new BufferedReader(new FileReader(file), 8 * 1024);
            String line;
            while ((line = br.readLine()) != null)
            {
               output.append(line + "\n");
            }
            tv.setText(output);
            setContentView(tv);
         }
         catch (Exception e)
         {
            e.printStackTrace();
         }
      }

      /* (non-Javadoc)
      * @see android.os.AsyncTask#onProgressUpdate(Progress[])
      */
     @Override
     protected void onProgressUpdate(Void... values)
      {

      }
}

tcpdump.sh has this line tcpdump -c 10> /data/local/bin/dump.txt

+3
source share
1 answer

Of course you mean to call Process.waitFor()?Notwait()?

+3
source

Source: https://habr.com/ru/post/1766518/


All Articles