Friday, October 18, 2013

stopping java threads...

So I'm looking up the best way to close a thread, and there's examples of stopping it with .interrupt().

That shit is whack cuz you gotta have the thread call something (either .wait() or .sleep() or something) that actually throws an InterruptedException in order for the Thread to intercept the interrupt.

So what if you don't need to sleep or wait? I'm not about to write unnecessary code in order to close a Thread "properly". I find that having a flag for my while loop works great and I can even control closing sockets properly and anything else that may be blocking the Thread.

There are definitely good reasons not to use .stop() since the API even says it's deprecated, on top of the weird Exceptions you could get.

No comments:

Post a Comment