On Thu, Oct 8, 2009 at 5:12 PM, Sandro Martini <[email protected]> wrote:
> So the real question, when an application executes many Threads (via > Pivot queues), there is a simple way (like an utility method) to > pause/resume also them ? The same also to kill all worker Threads > before exiting. A couple of things (general knowledge, not Pivot related); * The JVM supports something called "daemon" threads. The definition is that a running daemon thread will not hold the JVM hostage for stopping, like ordinary threads do. * Thread.suspend() and Thread.stop() should be avoided at all cost, since the JVM will not release the monitors held by the thread, which may lead to deadlocks. * All thread main loops should be constructed to ensure that the thread can be aborted via the Thread.interrupt() method. To do so, one need to have something in the thread that can yield. This can happen at OS level in blocking I/O, Object.wait(), Thread.sleep() and I think even yield() can be interrupted. The loop should catch InterruptedException and clean up its state then exit. Most "worker" solutions support this behind the scenes. Cheers -- Niclas Hedhman, Software Developer http://www.qi4j.org - New Energy for Java I live here; http://tinyurl.com/2qq9er I work here; http://tinyurl.com/2ymelc I relax here; http://tinyurl.com/2cgsug
