A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
Henry, I used a while(running) boolean to stop loops in the run() method for a long time, but then realized interrupt() and interruped() seem just right for the job. Is that a preferred way to signal the loop or sequence of steps that it should terminate?
Originally posted by Henry Wong:
Unfortunately, the recommended way to cause a thread to exit is to "arrange for it to exit" -- meaning setting some kind of "exit" flag that will be checked by the thread periodically.
The interrupt() does indeed cause certain methods to exit with an InterruptedException, but since it is a checked exception, I am willing to bet that you probably just ignore it and tried again. Furthermore, it is not guaranteed to work. For example, on Windows, I/O is not interruptable.
The stop() method is deprecated because of the way it works, it causes the thread to throw a throwable that is not checked (or even caught, as most developers didn't know about it). This had the effect of causing threads to exit in states that were not usable -- and in rare cases, even messing up some JVM internals.
So... no short cut to do this. You have to design an exit strategy for your child thread.
Henry
Originally posted by Ben Ethridge:
After reading the article, this appears to me to be a major design flaw in the java language, that everyone's just working around as best they can, yes?
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Originally posted by Peter Chase:
...the thread doing the killing often has no idea what the thread being killed might be in the middle of.
Originally posted by Ben Ethridge:
How is this any different than killing a unix process?
Ben
The problem with java, unlike unix, is that the designers decided that they know better than the users what they should and should not be allowed to kill easily, so they shut off the stop switch coz it didn't work.
Ruth Stout was famous for gardening naked. Just like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|