I've read several articles on how to stop Threads, and all of them point to using Thread.interrupt(). The problem right now is what happens when the thread is in an infinite loop. For example:
class A implements Runnable
{
public void run()
{
while(!Thread.currentThread().isInterrupted())
while(true);
}
}
//in other class's main method:
Thread a = new Thread(new A());
a.start();
a.interrupt();
The a.interrupt() call only sets the isInterrupted flag in Thread, but it does not terminate the thread as a.stop() would. However, stop() throws a ThreadDeath exception that I would not want to have to deal with. Is there any way to stop this infinite loop thread safely?
Thanks in advance!