Consider the following case:
main() {
ClassA insA = new ClassA();
insA.run();
}
ClassA.run() {
for(;;) {
RMI.call();
blahblah();
}
}
RMI.call()
is an RMI function which blocks the thread using Semaphore.acquire()
till something (in another thread) happens.
The question is: How can I safely kill all the threads?
defining a stop()
function in ClassA
like below:
stop() {
Thread.currentThread.interrupt();
}
and calling it from outside (e.g. main()
)will NOT interrupt the RMI call thread.
How can I interrupt the original thread, so I can exit the code properly?
Or any other way the exit safely?
Check this library: http://java.net/projects/interruptiblermi. Thread#interrupt() will not help.