public class ThreadController
Provides a simple Mechanism for creating, starting and stopping groups of threads which perform a specific task. This is considerably
more efficient than the Executor service for cases where all that is required is a constant set of threads which each perform a task
Create a new thread controller with a new ThreadGroup with the given name
name - String name of new ThreadGroup
tf - ThreadFactory to use to create the threads
public boolean isShutdown()
Query the shutdown status of the thread controller. This is mainly useful for controlled threads to use to query the state of the
controller. If true is returned they should shut themselves down at the earliest convenient opportunity.
boolean shutdown status true=shutting down, false=running or not yet started
public void shutdown()
Set the shutdown state to true. This is an advisory to controlled threads, they should check this status periodically to determine
if they should stop. This can be called when a gracefull shutdown of the controlled threads is desired, such as before application
public boolean stop(int timeout)
Initiates an unconditional shutdown of the controlled threads. 1st shutdown will be called and all threads will be given a bit of
time to terminate themselves gracefully. After that any remaining threads will be interrupted. Once all threads have died or a
time limit has expired this method will return.
timeout - int milliseconds to wait for threads before returning.
boolean true if all threads have exited, false otherwise
public void start(int numthreads)
Start the given number of threads.
numthreads - int number of threads to create
public void newThread()
public boolean restart(int numthreads,
Attempt a gracefull shutdown of all currently running threads and then start the indicated number of new threads. If some of the
old threads fail to stop within a reasonable time return false and do not start new threads, otherwise return true.
numthreads - int number of threads to restart
timeout - int number of milliseconds to wait for threads to stop
boolean true indicates restart was successful, false indicates some existing threads failed to stop