This is a short question. At some point my thread understand that it should suicide. What is the best way to do it:
If you simply call interrupt()
, the thread will not automatically be closed. Instead, the Thread might even continue living, if isInterrupted()
is implemented accordingly. The only way to guaranteedly close a thread, as asked for by OP, is
Thread.currentThread().stop();
Method is deprecated, however.
Calling return
only returns from the current method. This only terminates the thread if you're at its top level.
Nevertheless, you should work with interrupt()
and build your code around it.