2

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?

Community
  • 1
  • 1
Soheil
  • 1,676
  • 7
  • 34
  • 65
  • 5
    There's really no such thing as immidietly when it comes to threads as you are dependant on the schedueler. – Oren Jan 20 '13 at 11:50
  • Threads should cooperate with their own termination. It is the clean way to do things. Killing a non-cooperating thread can lead to strange problems (which is why stop() was deprecated). – tucuxi Jan 20 '13 at 11:54
  • see http://stackoverflow.com/questions/4530744/how-to-kill-a-thread-immediately-from-another-thread-in-java?rq=1, and many others – tucuxi Jan 20 '13 at 11:59

0 Answers0