Possible Duplicate:
How to kill a thread immediately from another thread in java?
How to properly stop the Thread in Java
I need a way to stop another Thread execution ass needed just on time, I mean without any delay, for example while the user clicks a button, the Thread stops it's execution immediately (not important what was doing).
I think a way is to submit that Runnable class via an ExecutorService
and cancel the returned Future while needed. at the other side I must check Thread.currentThread.isInterrupted()
and if that was true the thread returns.
But it has a problem, it doesn't work immediately. any better idea?