Eidola home

org.eidola.util
Class ThreadFlock

java.lang.Object
  |
  +--org.eidola.util.ThreadFlock

public class ThreadFlock
extends Object

Creates a collection of threads running the same Runnable. The threads have the same priority and the same daemon status. You can start, interrupt, and join the threads en masse.

Version:
[Development version]
Author:
Paul Cantrell

Constructor Summary
ThreadFlock(Runnable runnable)
          Creates a new flock with one thread.
ThreadFlock(Runnable runnable, int threadCount)
          Creates a new flock with an arbitrary number of threads.
ThreadFlock(Thread thread)
          Creates a new flock with one thread.
ThreadFlock(Thread thread, int threadCount)
          Creates a new flock with an arbitrary number of threads.
 
Method Summary
 int getPriority()
          Returns the priority of the threads in this flock.
 int getThreadCount()
          Returns the number of threads in this flock.
 void interrupt()
          Interrupts all the threads in the flock.
 boolean isDaemon()
          Determines whether the threads in this flock are daemons.
 void join(long time)
          Waits for all the threads in the flock to die.
 void setDaemon(boolean daemon)
          Changes whether the threads in this flock are daemons.
 void setPriority(int priority)
          Sets the priority of all the threads in this flock.
 void setThreadCount(int threadCount, boolean start)
          Sets the number of threads in this flock.
 void start()
          Starts all the threads in the flock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadFlock

public ThreadFlock(Runnable runnable)
Creates a new flock with one thread. To start the threads, use start().

ThreadFlock

public ThreadFlock(Runnable runnable,
                   int threadCount)
Creates a new flock with an arbitrary number of threads. To start the threads, use start().

ThreadFlock

public ThreadFlock(Thread thread)
Creates a new flock with one thread. The flock takes the priority and daemon status of the thread parameter, but that thread does not actually become a member of the flock. To start the threads, use start().

ThreadFlock

public ThreadFlock(Thread thread,
                   int threadCount)
Creates a new flock with an arbitrary number of threads. The flock takes the priority and daemon status of the thread parameter, but that thread does not actually become a member of the flock. To start the threads, use start().
Method Detail

getThreadCount

public int getThreadCount()
Returns the number of threads in this flock.

setThreadCount

public void setThreadCount(int threadCount,
                           boolean start)
Sets the number of threads in this flock. If this is an increase, this method will create the new threads, and will start them if the start parameter is true. If this is a decrease, this method will interrupt the appropriate number of threads.

getPriority

public int getPriority()
Returns the priority of the threads in this flock. Note that each individual thread has this priority, so a flock with 50 threads of normal priority is actually an extremely high-priority flock.
See Also:
Thread.getPriority()

setPriority

public void setPriority(int priority)
Sets the priority of all the threads in this flock. This affects threads whether or not they are running, and affects any threads created by subsequent calls to setThreadCount.
See Also:
Thread.setPriority(int)

isDaemon

public boolean isDaemon()
Determines whether the threads in this flock are daemons. (Daemon threads die automatically when the Java VM goes away.)
See Also:
Thread.isDaemon()

setDaemon

public void setDaemon(boolean daemon)
Changes whether the threads in this flock are daemons. This affects threads whether or not they are running, and affects any threads created by subsequent calls to setThreadCount.
See Also:
Thread.setDaemon(boolean)

start

public void start()
Starts all the threads in the flock.
See Also:
Thread.start()

interrupt

public void interrupt()
Interrupts all the threads in the flock.
See Also:
Thread.interrupt()

join

public void join(long time)
          throws InterruptedException
Waits for all the threads in the flock to die.
See Also:
Thread.join(long)

Eidola home