我有一段关于Android的代码,它卡在了synchronized语句。即使我移除了process1.wait(),我仍然捕获到异常。任何帮助都将不胜感激。
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文件中有这一行代码:
tcpdump -c 10 > /data/local/bin/dump.txt