RTA*_*RTA 3 java multithreading runtime
在我的应用程序中,我正在使用运行批处理文件的代码,在执行它时我收到一个异常,即当前线程不是所有者。这里要提一下,我的应用是基于eclipse插件开发的。以下是我的代码,请查看并找出问题以帮助我..
/*.......any code.........*/
try
{
Runtime runtime = Runtime.getRuntime();
String cmd = new String(C:\\abc.bat);
process = runtime.exec("\"" + cmd + "\"");
process.wait();
}
catch (Exception e)
{
e.printStackTrace();
}
/***********any code**************/
Run Code Online (Sandbox Code Playgroud)
等待是Object拥有的方法,要使用该方法,你必须拿到对象的锁,把你的代码改成,
try
{
Runtime runtime = Runtime.getRuntime();
String cmd = new String(C:\\abc.bat);
process = runtime.exec("\"" + cmd + "\"");
synchronized (process){
try{
process.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13547 次 |
最近记录: |