posted 17 years ago
This is a frequently-asked question. It may even actually be in the JavaRanch FAQ.
Anyway, there is no safe way forcibly to stop another thread. You must not, however tempting it may seem, use the deprecated methods like Thread.stop(), because your application will foul-up (not every time you run it, but intermittently and confusingly).
You have to devise a way by which the threads of your application can co-operate, to decide when they should finish. Thread.interrupt() can be useful for that, or the threads may share some shut-down flag.
By the way, if all you want to do is stop a long-running thread at application shut-down, you may only need to make the long-running thread a daemon thread (using Thread.setDaemon()). Then it will automatically stop when all non-daemon threads have stopped.
[ June 30, 2006: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.