com.caucho.env.thread2
Class ThreadPool2

java.lang.Object
  extended by com.caucho.env.thread2.ThreadPool2
All Implemented Interfaces:
java.util.concurrent.Executor
Direct Known Subclasses:
ThreadPool

public class ThreadPool2
extends java.lang.Object
implements java.util.concurrent.Executor

A generic pool of threads available for Alarms and Work tasks.


Field Summary
static java.lang.String THREAD_FULL_EVENT
           
 
Constructor Summary
ThreadPool2()
           
ThreadPool2(java.lang.String name)
           
 
Method Summary
 void clearIdleThreads()
          interrupts all the idle threads.
 void close()
           
 void closeEnvironment(java.lang.ClassLoader env)
          Resets the thread pool, letting old threads drain.
 void execute(java.lang.Runnable task)
           
static ThreadPool2 getCurrent()
           
 int getFreeThreadCount()
          Returns the free thread count.
 int getIdleMax()
          Returns the thread idle max.
 int getIdleMin()
          Gets the minimum number of idle threads.
 long getIdleTimeout()
          Returns the idle timeout.
 int getPriorityIdleMin()
           
 int getThreadActiveCount()
          Returns the active thread count.
 int getThreadCount()
          Returns the total thread count.
 long getThreadCreateCountTotal()
          Returns the total created thread count.
 int getThreadIdleCount()
          Returns the idle thread count.
 int getThreadMax()
          Gets the maximum number of threads.
 long getThreadOverflowCountTotal()
          Returns the total created overflow thread count.
 int getThreadPriorityQueueSize()
          Returns priority queue size
 int getThreadStartingCount()
          Returns the starting thread count.
 int getThreadTaskQueueSize()
          Returns task queue size
 int getThreadWaitCount()
          Returns the waiting thread count.
 void reset()
          Resets the thread pool, letting old threads drain.
 boolean schedule(java.lang.Runnable task)
          Schedules a new task.
 boolean schedule(java.lang.Runnable task, java.lang.ClassLoader loader)
          Schedules a new task.
 boolean schedule(java.lang.Runnable task, long timeout)
          Adds a new task.
protected  boolean scheduleImpl(java.lang.Runnable task, java.lang.ClassLoader loader, long expireTime, boolean isPriority, boolean isQueueIfFull, boolean isWakeScheduler)
          main scheduling implementation class.
 void schedulePriority(java.lang.Runnable task)
          Adds a new task.
 void scheduleUnpark(java.lang.Thread thread)
           
protected  void setAsGlobal(ThreadPool2 pool)
           
 void setIdleMax(int idleMax)
          Returns the thread idle max.
 void setIdleMin(int min)
          Sets the minimum number of idle threads.
 void setIdleTimeout(long timeout)
          Sets the idle timeout
 void setPriorityIdleMin(int min)
          Sets the minimum number of free threads reserved for priority tasks.
 void setThreadMax(int max)
          Sets the maximum number of threads.
 void setThrottleLimit(int limit)
          Sets the throttle limit.
 void setThrottlePeriod(long period)
          Sets the throttle period.
 void setThrottleSleepTime(long period)
          Sets the throttle sleep time.
 void start()
           
 boolean start(java.lang.Runnable task)
          Adds a new task.
 boolean start(java.lang.Runnable task, long timeout)
          Adds a new task.
 void startPriority(java.lang.Runnable task)
          Adds a new task.
 boolean startPriority(java.lang.Runnable task, long timeout)
          Adds a new task.
 boolean submitNoWake(java.lang.Runnable task)
          Submit a task, but do not wake the scheduler
 boolean submitNoWake(java.lang.Runnable task, java.lang.ClassLoader loader)
          Submit a task, but do not wake the scheduler
 java.lang.String toString()
           
 void wakeScheduler()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

THREAD_FULL_EVENT

public static final java.lang.String THREAD_FULL_EVENT
See Also:
Constant Field Values
Constructor Detail

ThreadPool2

public ThreadPool2()

ThreadPool2

public ThreadPool2(java.lang.String name)
Method Detail

getCurrent

public static ThreadPool2 getCurrent()

setAsGlobal

protected void setAsGlobal(ThreadPool2 pool)

setThreadMax

public void setThreadMax(int max)
Sets the maximum number of threads.


getThreadMax

public int getThreadMax()
Gets the maximum number of threads.


setIdleMin

public void setIdleMin(int min)
Sets the minimum number of idle threads.


getIdleMin

public int getIdleMin()
Gets the minimum number of idle threads.


getIdleMax

public int getIdleMax()
Returns the thread idle max.


setIdleMax

public void setIdleMax(int idleMax)
Returns the thread idle max.


setPriorityIdleMin

public void setPriorityIdleMin(int min)
Sets the minimum number of free threads reserved for priority tasks.


getPriorityIdleMin

public int getPriorityIdleMin()

setIdleTimeout

public void setIdleTimeout(long timeout)
Sets the idle timeout


getIdleTimeout

public long getIdleTimeout()
Returns the idle timeout.


setThrottlePeriod

public void setThrottlePeriod(long period)
Sets the throttle period.


setThrottleLimit

public void setThrottleLimit(int limit)
Sets the throttle limit.


setThrottleSleepTime

public void setThrottleSleepTime(long period)
Sets the throttle sleep time.


getThreadCount

public int getThreadCount()
Returns the total thread count.


getThreadActiveCount

public int getThreadActiveCount()
Returns the active thread count.


getThreadStartingCount

public int getThreadStartingCount()
Returns the starting thread count.


getThreadIdleCount

public int getThreadIdleCount()
Returns the idle thread count.


getThreadWaitCount

public int getThreadWaitCount()
Returns the waiting thread count.


getFreeThreadCount

public int getFreeThreadCount()
Returns the free thread count.


getThreadCreateCountTotal

public long getThreadCreateCountTotal()
Returns the total created thread count.


getThreadOverflowCountTotal

public long getThreadOverflowCountTotal()
Returns the total created overflow thread count.


getThreadPriorityQueueSize

public int getThreadPriorityQueueSize()
Returns priority queue size


getThreadTaskQueueSize

public int getThreadTaskQueueSize()
Returns task queue size


start

public void start()

execute

public void execute(java.lang.Runnable task)
Specified by:
execute in interface java.util.concurrent.Executor

schedule

public boolean schedule(java.lang.Runnable task)
Schedules a new task.


schedule

public boolean schedule(java.lang.Runnable task,
                        java.lang.ClassLoader loader)
Schedules a new task.


schedule

public boolean schedule(java.lang.Runnable task,
                        long timeout)
Adds a new task.


schedulePriority

public void schedulePriority(java.lang.Runnable task)
Adds a new task.


start

public boolean start(java.lang.Runnable task)
Adds a new task.


start

public boolean start(java.lang.Runnable task,
                     long timeout)
Adds a new task.


startPriority

public void startPriority(java.lang.Runnable task)
Adds a new task.


startPriority

public boolean startPriority(java.lang.Runnable task,
                             long timeout)
Adds a new task.


submitNoWake

public boolean submitNoWake(java.lang.Runnable task)
Submit a task, but do not wake the scheduler


submitNoWake

public boolean submitNoWake(java.lang.Runnable task,
                            java.lang.ClassLoader loader)
Submit a task, but do not wake the scheduler


scheduleImpl

protected boolean scheduleImpl(java.lang.Runnable task,
                               java.lang.ClassLoader loader,
                               long expireTime,
                               boolean isPriority,
                               boolean isQueueIfFull,
                               boolean isWakeScheduler)
main scheduling implementation class.


wakeScheduler

public void wakeScheduler()

scheduleUnpark

public final void scheduleUnpark(java.lang.Thread thread)

reset

public void reset()
Resets the thread pool, letting old threads drain.


closeEnvironment

public void closeEnvironment(java.lang.ClassLoader env)
Resets the thread pool, letting old threads drain.


clearIdleThreads

public void clearIdleThreads()
interrupts all the idle threads.


close

public void close()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object