spj spj - 1 year ago 87
Java Question

How to stop the thread in a ThreadPool in a suggested way?

I am keen on knowing a good way to stop the thread I want to ? Please give me some suggestion . Thank you !

Answer Source

Using Thread.interrupt() is a perfectly acceptable way of doing this. In fact, it's probably preferrable over using a flag. The reason being that if you're in an interruptable blocking call (like Thread.sleep or using java.nio Channel operations), you'll actually be able to break out of those right away.

You can find some reasonable alternatives in this post - How to properly stop the Thread in Java?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download