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**************/
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.
The java. lang. Thread. currentThread() method returns a reference to the currently executing thread object.
The wait function doesn't release "all locks", but it does release the lock associated with the object on which wait is invoked.
Use Thread. sleep(1000) ; 1000 is the number of milliseconds that the program will pause.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With