当前线程不是所有者例外 [英] Current thread not owner exception

查看:131
本文介绍了当前线程不是所有者例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中我正在使用运行批处理文件的代码,在执行它时我得到一个例外,即当前线程不是所有者。
这里我想提一下我的应用程序是基于eclipse插件开发的。
以下是我的代码,请看一下,看看有什么问题可以帮助我..

in my application i am using a code that run a batch file, on executing it i am getting a exception i.e. current thread is not owner. Here i want to mention that my application is based on eclipse plugin development. Following is my code, please have a look and find out what is the problem to help me..

/*.......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**************/


推荐答案

等待是Object拥有的方法,要使用该方法,必须获取锁定对象,将代码更改为,

The wait is the method owned by Object, to use the method, you must get the lock of the object, change your code to,

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();
}

这篇关于当前线程不是所有者例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆