Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current thread not owner exception

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**************/
like image 413
RTA Avatar asked May 24 '13 07:05

RTA


People also ask

What happens if there is Exception in thread?

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.

How do you get reference to the current thread in Java?

The java. lang. Thread. currentThread() method returns a reference to the currently executing thread object.

Does wait release lock in Java?

The wait function doesn't release "all locks", but it does release the lock associated with the object on which wait is invoked.

How do I sleep Java?

Use Thread. sleep(1000) ; 1000 is the number of milliseconds that the program will pause.


1 Answers

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();
}
like image 187
Stony Avatar answered Sep 23 '22 01:09

Stony