org.eclipse.jetty.util.thread
Class OldQueuedThreadPool

java.lang.Object
  extended by org.eclipse.jetty.util.component.AbstractLifeCycle
      extended by org.eclipse.jetty.util.thread.OldQueuedThreadPool
All Implemented Interfaces:
Serializable, LifeCycle, ThreadPool

public class OldQueuedThreadPool
extends AbstractLifeCycle
implements Serializable, ThreadPool

A pool of threads.

Avoids the expense of thread creation by pooling threads after their run methods exit for reuse.

If an idle thread is available a job is directly dispatched, otherwise the job is queued. After queuing a job, if the total number of threads is less than the maximum pool size, a new thread is spawned.

See Also:
Serialized Form

Nested Class Summary
 class OldQueuedThreadPool.PoolThread
          Pool Thread class.
 
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
 
Field Summary
 
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
 
Constructor Summary
OldQueuedThreadPool()
           
OldQueuedThreadPool(int maxThreads)
           
 
Method Summary
 boolean dispatch(Runnable job)
          Run job.
protected  void doStart()
           
protected  void doStop()
          Stop the BoundedThreadPool.
 int getIdleThreads()
          Get the number of idle threads in the pool.
 int getLowThreads()
           
 int getMaxIdleTimeMs()
          Get the maximum thread idle time.
 int getMaxQueued()
           
 int getMaxStopTimeMs()
           
 int getMaxThreads()
          Set the maximum number of threads.
 int getMinThreads()
          Get the minimum number of threads.
 String getName()
           
 int getQueueSize()
           
 int getSpawnOrShrinkAt()
           
 int getThreads()
          Get the number of threads in the pool.
 int getThreadsPriority()
          Get the priority of the pool threads.
 boolean isDaemon()
          Delegated to the named or anonymous Pool.
 boolean isLowOnThreads()
           
 void join()
          Blocks until the thread pool is stopped.
protected  void newThread()
           
 void setDaemon(boolean daemon)
          Delegated to the named or anonymous Pool.
 void setLowThreads(int lowThreads)
           
 void setMaxIdleTimeMs(int maxIdleTimeMs)
          Set the maximum thread idle time.
 void setMaxStopTimeMs(int stopTimeMs)
           
 void setMaxThreads(int maxThreads)
          Set the maximum number of threads.
 void setMinThreads(int minThreads)
          Set the minimum number of threads.
 void setName(String name)
           
 void setSpawnOrShrinkAt(int spawnOrShrinkAt)
           
 void setThreadsPriority(int priority)
          Set the priority of the pool threads.
protected  void stopJob(Thread thread, Object job)
          Stop a Job.
 
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OldQueuedThreadPool

public OldQueuedThreadPool()

OldQueuedThreadPool

public OldQueuedThreadPool(int maxThreads)
Method Detail

dispatch

public boolean dispatch(Runnable job)
Run job.

Specified by:
dispatch in interface ThreadPool
Returns:
true

getIdleThreads

public int getIdleThreads()
Get the number of idle threads in the pool.

Specified by:
getIdleThreads in interface ThreadPool
Returns:
Number of threads
See Also:
getThreads()

getLowThreads

public int getLowThreads()
Returns:
low resource threads threshhold

getMaxQueued

public int getMaxQueued()
Returns:
maximum queue size

getMaxIdleTimeMs

public int getMaxIdleTimeMs()
Get the maximum thread idle time. Delegated to the named or anonymous Pool.

Returns:
Max idle time in ms.
See Also:
setMaxIdleTimeMs(int)

getMaxThreads

public int getMaxThreads()
Set the maximum number of threads. Delegated to the named or anonymous Pool.

Returns:
maximum number of threads.
See Also:
setMaxThreads(int)

getMinThreads

public int getMinThreads()
Get the minimum number of threads. Delegated to the named or anonymous Pool.

Returns:
minimum number of threads.
See Also:
setMinThreads(int)

getName

public String getName()
Returns:
The name of the BoundedThreadPool.

getThreads

public int getThreads()
Get the number of threads in the pool.

Specified by:
getThreads in interface ThreadPool
Returns:
Number of threads
See Also:
getIdleThreads()

getThreadsPriority

public int getThreadsPriority()
Get the priority of the pool threads.

Returns:
the priority of the pool threads.

getQueueSize

public int getQueueSize()

getSpawnOrShrinkAt

public int getSpawnOrShrinkAt()
Returns:
the spawnOrShrinkAt The number of queued jobs (or idle threads) needed before the thread pool is grown (or shrunk)

setSpawnOrShrinkAt

public void setSpawnOrShrinkAt(int spawnOrShrinkAt)
Parameters:
spawnOrShrinkAt - The number of queued jobs (or idle threads) needed before the thread pool is grown (or shrunk)

getMaxStopTimeMs

public int getMaxStopTimeMs()
Returns:
maximum total time that stop() will wait for threads to die.

setMaxStopTimeMs

public void setMaxStopTimeMs(int stopTimeMs)
Parameters:
stopTimeMs - maximum total time that stop() will wait for threads to die.

isDaemon

public boolean isDaemon()
Delegated to the named or anonymous Pool.


isLowOnThreads

public boolean isLowOnThreads()
Specified by:
isLowOnThreads in interface ThreadPool
Returns:
True if the pool is low on threads

join

public void join()
          throws InterruptedException
Description copied from interface: ThreadPool
Blocks until the thread pool is stopped.

Specified by:
join in interface ThreadPool
Throws:
InterruptedException

setDaemon

public void setDaemon(boolean daemon)
Delegated to the named or anonymous Pool.


setLowThreads

public void setLowThreads(int lowThreads)
Parameters:
lowThreads - low resource threads threshhold

setMaxIdleTimeMs

public void setMaxIdleTimeMs(int maxIdleTimeMs)
Set the maximum thread idle time. Threads that are idle for longer than this period may be stopped. Delegated to the named or anonymous Pool.

Parameters:
maxIdleTimeMs - Max idle time in ms.
See Also:
getMaxIdleTimeMs()

setMaxThreads

public void setMaxThreads(int maxThreads)
Set the maximum number of threads. Delegated to the named or anonymous Pool.

Parameters:
maxThreads - maximum number of threads.
See Also:
getMaxThreads()

setMinThreads

public void setMinThreads(int minThreads)
Set the minimum number of threads. Delegated to the named or anonymous Pool.

Parameters:
minThreads - minimum number of threads
See Also:
getMinThreads()

setName

public void setName(String name)
Parameters:
name - Name of the BoundedThreadPool to use when naming Threads.

setThreadsPriority

public void setThreadsPriority(int priority)
Set the priority of the pool threads.

Parameters:
priority - the new thread priority.

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class AbstractLifeCycle
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Stop the BoundedThreadPool. New jobs are no longer accepted,idle threads are interrupted and stopJob is called on active threads. The method then waits min(getMaxStopTimeMs(),getMaxIdleTimeMs()), for all jobs to stop, at which time killJob is called.

Overrides:
doStop in class AbstractLifeCycle
Throws:
Exception

newThread

protected void newThread()

stopJob

protected void stopJob(Thread thread,
                       Object job)
Stop a Job. This method is called by the Pool if a job needs to be stopped. The default implementation does nothing and should be extended by a derived thread pool class if special action is required.

Parameters:
thread - The thread allocated to the job, or null if no thread allocated.
job - The job object passed to run.


Copyright © 1995-2009 Mort Bay Consulting. All Rights Reserved.