Unknown Java

A fact on java that many people do not realize: it is not trivial to actually “stop” a thread. All the methods like “destroy()” and the likes are depcrecated and have been for a long time because these methods are NOT safe to use.

I am currently in the process of finding out how to stop java from doing something like continuing an infinite loop nested deeply within a method call of a library. I’ll post my solution or the reason why it won’t work.

Addition: must correct myself “destroy” is not deprecated: it was never implemented. But “stop, resume and suspend” are deprecated. For those who think that by assigning “null” to the variable that you kept the reference to the thread in: go back to learning basic java principles. No not really: there is always a reference in some ThreadGroup object to all threads running. But everybody should know that assigning “null” to something is code smell or rather stink!

3 Replies to “Unknown Java”

  1. If there’s an infinite loop in your library (or something to that effect) it is broken. I don’t see this can be handled in a nice way – any attempt to force such a thread down will be equal to stop(). Which means it’s potentially more harmful than just leaving the thread around.

  2. I just posted something to that effect to the list 😉 But sadly you are right I think 🙁 Many people keep thinking though that running something in its own thread will solve any problems happening within that method call and it does not. So wish me happy debugging. If the lib wasn’t OS software I’d be killing somebody right now.

  3. Oh and: leaving the thread around is very harmful since it is causing an awful amount of load and of course where there is one there will soon be many by the same principle as “go forth and multiply” …. I’ll just find and have it fixed.

Comments are closed.