org.eclipse.jetty.util.thread
Class QueuedThreadPool

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

public class QueuedThreadPool
extends AbstractLifeCycle
implements ThreadPool, Executor


Nested Class Summary
 
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
QueuedThreadPool()
           
QueuedThreadPool(BlockingQueue<Runnable> jobQ)
           
QueuedThreadPool(int maxThreads)
           
 
Method Summary
 boolean dispatch(Runnable job)
           
protected  void doStart()
           
protected  void doStop()
           
 String dump()
           
 String dumpThread(long id)
           
 void execute(Runnable job)
           
 int getIdleThreads()
           
 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 getThreads()
           
 int getThreadsPriority()
          Get the priority of the pool threads.
 boolean interruptThread(long id)
           
 boolean isDaemon()
          Delegated to the named or anonymous Pool.
 boolean isLowOnThreads()
           
 void join()
          Blocks until the thread pool is stopped.
protected  Thread newThread(Runnable runnable)
           
 void setDaemon(boolean daemon)
          Delegated to the named or anonymous Pool.
 void setMaxIdleTimeMs(int maxIdleTimeMs)
          Set the maximum thread idle time.
 void setMaxQueued(int max)
           
 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 setThreadsPriority(int priority)
          Set the priority of the pool threads.
 boolean stopThread(long id)
           
 String toString()
           
 
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, wait, wait, wait
 

Constructor Detail

QueuedThreadPool

public QueuedThreadPool()

QueuedThreadPool

public QueuedThreadPool(int maxThreads)

QueuedThreadPool

public QueuedThreadPool(BlockingQueue<Runnable> jobQ)
Method Detail

doStart

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

doStop

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

setDaemon

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


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()

setMaxStopTimeMs

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

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.

getMaxQueued

public int getMaxQueued()
Returns:
maximum queue size

setMaxQueued

public void setMaxQueued(int max)
Parameters:
max - job 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)

getMaxStopTimeMs

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

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.

getThreadsPriority

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

Returns:
the priority of the pool threads.

isDaemon

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


dispatch

public boolean dispatch(Runnable job)
Specified by:
dispatch in interface ThreadPool

execute

public void execute(Runnable job)
Specified by:
execute in interface Executor

join

public void join()
          throws InterruptedException
Blocks until the thread pool is stopped.

Specified by:
join in interface ThreadPool
Throws:
InterruptedException

getThreads

public int getThreads()
Specified by:
getThreads in interface ThreadPool
Returns:
The total number of threads currently in the pool

getIdleThreads

public int getIdleThreads()
Specified by:
getIdleThreads in interface ThreadPool
Returns:
The number of idle threads in the pool

isLowOnThreads

public boolean isLowOnThreads()
Specified by:
isLowOnThreads in interface ThreadPool
Returns:
True if the pool is at maxThreads and there are more queued jobs than idle threads

newThread

protected Thread newThread(Runnable runnable)

toString

public String toString()
Overrides:
toString in class Object

dump

public String dump()

stopThread

public boolean stopThread(long id)
Parameters:
id - The thread ID to stop.
Returns:
true if the thread was found and stopped.

interruptThread

public boolean interruptThread(long id)
Parameters:
id - The thread ID to interrupt.
Returns:
true if the thread was found and interrupted.

dumpThread

public String dumpThread(long id)
Parameters:
id - The thread ID to interrupt.
Returns:
true if the thread was found and interrupted.


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