Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Stopping/Interrupting ProcessBuilder Thread

626385Mar 9 2009 — edited Mar 10 2009
Hello,

I looked through all the topics and couldn't find what I actually wanted.

What did I do?_
I created a thread for a ProcessBuilder which creates a new JVM to run a process.
Eg:
Thread thread = new Thread(threadGroup, threadName){
   public void run(){
     ProcessBuilder pb = new ProcessBuilder("java.exe", "-cp", "<path to the jar file>", "<main class in the JAR>", <arg1>, <arg2>);
     pb.directory(<working-directory>);
     .....
     Process process = pb.start();
     ...
   }
};
thread.start();
What I want?_
I have a JSP which displays the list of threads running in the application. And, the above thread is one of them. There's also a facility to stop the threads (actually it's interrupting). This works perfectly alright for all the threads except the above thread. When the STOP button is clicked to stop(i.e., to interrupt), the JSP shows the thread is interrupted but I could see the thread to go to completion even after. I even debugged the code and found that thread.interrupt();+ is getting executed for the above thread but it's not really interrupting the thread.

What I think is happening?_
As the thread is creating a new process in the new JVM, the application that's running in the original JVM doesn't have control over that process.

Solution?_
If I'm thinking in the right direction, then is there a solution for this?
How can I get that thread to stop/interrupt?

Any help is really appreciated.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2009
Added on Mar 9 2009
6 comments
891 views