org.garret.jsql
Class ThreadPool

java.lang.Object
  extended byorg.garret.jsql.ThreadPool

public class ThreadPool
extends java.lang.Object

Pool of threads used to minimize overhead of creation new threads each time it is needed


Constructor Summary
ThreadPool()
          Constructor of thread pool with unlimited number of threads
ThreadPool(int maxThreads)
          Constructor of thread pool with limited number of threads
 
Method Summary
 void close()
          Wait termination of all active tasks and stop all threads in thread pool
static ThreadPool getInstance()
          Get instance of thread pool
 void join(java.lang.Thread thread)
          Wait completion of task
 java.lang.Thread start(java.lang.Runnable task)
          Get thread from thread pool and start specified task in this thread
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(int maxThreads)
Constructor of thread pool with limited number of threads


ThreadPool

public ThreadPool()
Constructor of thread pool with unlimited number of threads

Method Detail

getInstance

public static ThreadPool getInstance()
Get instance of thread pool


start

public java.lang.Thread start(java.lang.Runnable task)
Get thread from thread pool and start specified task in this thread

Parameters:
task - class impkemeting Runnable interface which run method will be executed by pooled thread
Returns:
pooled thread (it should be used only in ThreadPool.join method)

join

public void join(java.lang.Thread thread)
          throws java.lang.InterruptedException
Wait completion of task

Parameters:
thread - pooled thread assigned to the task by ThreadPool.start method
Throws:
java.lang.InterruptedException

close

public void close()
Wait termination of all active tasks and stop all threads in thread pool