|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.concurrent.AbstractExecutorService
com.sun.grizzly.util.AbstractThreadPool
public abstract class AbstractThreadPool
Abstract ExtendedThreadPool
implementation.
Nested Class Summary | |
---|---|
class |
AbstractThreadPool.Worker
|
Field Summary | |
---|---|
protected int |
activeThreadsCount
|
protected ByteBufferFactory.ByteBufferType |
byteBufferType
The ByteBufferFactory.ByteBufferType |
protected int |
corePoolSize
|
protected int |
currentPoolSize
|
static int |
DEFAULT_IDLE_THREAD_KEEPALIVE_TIMEOUT
|
static int |
DEFAULT_MAX_TASKS_QUEUED
|
static int |
DEFAULT_MAX_THREAD_COUNT
|
static int |
DEFAULT_MIN_THREAD_COUNT
|
protected int |
initialByteBufferSize
The initial ByteBuffer size for newly created WorkerThread instances |
protected long |
keepAliveTime
|
protected int |
maxPoolSize
|
protected String |
name
|
protected static Runnable |
poison
|
protected int |
priority
Threads priority |
protected ThreadPoolMonitoringProbe |
probe
|
protected boolean |
running
|
protected Object |
statelock
|
protected ThreadFactory |
threadFactory
|
protected Map<AbstractThreadPool.Worker,Long> |
workers
|
Constructor Summary | |
---|---|
AbstractThreadPool(ThreadPoolMonitoringProbe probe,
String name,
ThreadFactory threadFactory,
int maxPoolSize)
|
Method Summary | |
---|---|
protected void |
afterExecute(Thread thread,
Runnable r,
Throwable t)
Method invoked upon completion of execution of the given Runnable. |
protected void |
beforeExecute(Thread t,
Runnable r)
Method invoked prior to executing the given Runnable in the given thread. |
protected static void |
drain(Queue<Runnable> from,
Collection<Runnable> too)
|
ByteBufferFactory.ByteBufferType |
getByteBufferType()
|
int |
getCorePoolSize()
Returns the core number of threads. |
protected ThreadFactory |
getDefaultThreadFactory()
|
int |
getInitialByteBufferSize()
|
long |
getKeepAliveTime(TimeUnit unit)
Returns the thread keep-alive time, which is the amount of time which threads in excess of the core pool size may remain idle before being terminated. |
int |
getMaximumPoolSize()
Returns the maximum allowed number of threads. |
String |
getName()
|
int |
getPriority()
|
ThreadFactory |
getThreadFactory()
Returns the thread factory used to create new threads. |
boolean |
isShutdown()
|
protected String |
nextThreadId()
|
protected void |
onMaxNumberOfThreadsReached()
Method is called by AbstractThreadPool, when maximum number of worker threads is reached and task will need to wait in task queue, until one of the threads will be able to process it. |
protected void |
onTaskCompletedEvent(Runnable task)
This method will be invoked when a the specified Runnable has
completed execution. |
protected void |
onTaskDequeued(Runnable task)
Method is called by a thread pool each time a task has been dequeued from a task queue. |
protected void |
onTaskQueued(Runnable task)
Method is called by a thread pool each time new task has been queued to a task queue. |
protected void |
onTaskQueueOverflow()
Method is called by a thread pool, when new task could not be added to a task queue, because task queue is full. |
protected void |
onWorkerExit(AbstractThreadPool.Worker worker)
Method is called by AbstractThreadPool.Worker , when it's completing
AbstractThreadPool.Worker.run() method execution, which in most cases means,
that ThreadPool's thread will be released. |
protected void |
onWorkerStarted(AbstractThreadPool.Worker worker)
Method is called by AbstractThreadPool.Worker , when it's starting
AbstractThreadPool.Worker.run() method execution, which means, that ThreadPool's
thread is getting active and ready to process tasks. |
protected void |
poisonAll()
|
void |
setByteBufferType(ByteBufferFactory.ByteBufferType byteBufferType)
|
void |
setCorePoolSize(int corePoolSize)
Sets the core number of threads. |
void |
setInitialByteBufferSize(int initialByteBufferSize)
|
void |
setKeepAliveTime(long time,
TimeUnit unit)
Sets the time limit for which threads may remain idle before being terminated. |
void |
setMaximumPoolSize(int maximumPoolSize)
Sets the maximum allowed number of threads. |
void |
setName(String name)
|
void |
setPriority(int priority)
|
void |
setThreadFactory(ThreadFactory threadFactory)
Sets the thread factory used to create new threads. |
void |
shutdown()
|
List<Runnable> |
shutdownNow()
|
protected void |
startWorker(AbstractThreadPool.Worker wt)
must hold statelock while calling this method. |
String |
toString()
|
void |
uncaughtException(Thread thread,
Throwable throwable)
|
protected void |
validateNewPoolSize(int corePoolsize,
int maxPoolSize)
|
Methods inherited from class java.util.concurrent.AbstractExecutorService |
---|
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.sun.grizzly.util.ExtendedThreadPool |
---|
getActiveCount, getCompletedTaskCount, getLargestPoolSize, getMaxQueuedTasksCount, getPoolSize, getQueue, getQueueSize, getTaskCount, setMaxQueuedTasksCount |
Methods inherited from interface java.util.concurrent.ExecutorService |
---|
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isTerminated, submit, submit, submit |
Methods inherited from interface java.util.concurrent.Executor |
---|
execute |
Field Detail |
---|
public static int DEFAULT_MIN_THREAD_COUNT
public static int DEFAULT_MAX_THREAD_COUNT
public static int DEFAULT_MAX_TASKS_QUEUED
public static int DEFAULT_IDLE_THREAD_KEEPALIVE_TIMEOUT
protected static final Runnable poison
protected volatile int initialByteBufferSize
protected volatile ByteBufferFactory.ByteBufferType byteBufferType
ByteBufferFactory.ByteBufferType
protected volatile String name
protected volatile int priority
protected volatile int corePoolSize
protected volatile int maxPoolSize
protected volatile long keepAliveTime
protected volatile ThreadFactory threadFactory
protected final ThreadPoolMonitoringProbe probe
protected final Object statelock
protected final Map<AbstractThreadPool.Worker,Long> workers
protected volatile boolean running
protected int currentPoolSize
protected int activeThreadsCount
Constructor Detail |
---|
public AbstractThreadPool(ThreadPoolMonitoringProbe probe, String name, ThreadFactory threadFactory, int maxPoolSize)
Method Detail |
---|
protected void startWorker(AbstractThreadPool.Worker wt)
wt
- public List<Runnable> shutdownNow()
shutdownNow
in interface ExecutorService
public void shutdown()
shutdown
in interface ExecutorService
public boolean isShutdown()
isShutdown
in interface ExecutorService
protected void poisonAll()
protected static final void drain(Queue<Runnable> from, Collection<Runnable> too)
protected String nextThreadId()
public String getName()
getName
in interface ExtendedThreadPool
public void setName(String name)
setName
in interface ExtendedThreadPool
public int getCorePoolSize()
getCorePoolSize
in interface ExtendedThreadPool
ExtendedThreadPool.setCorePoolSize(int)
public void setCorePoolSize(int corePoolSize)
setCorePoolSize
in interface ExtendedThreadPool
corePoolSize
- the new core sizeExtendedThreadPool.getCorePoolSize()
public int getMaximumPoolSize()
getMaximumPoolSize
in interface ExtendedThreadPool
ExtendedThreadPool.setMaximumPoolSize(int)
public void setMaximumPoolSize(int maximumPoolSize)
setMaximumPoolSize
in interface ExtendedThreadPool
maximumPoolSize
- the new maximumExtendedThreadPool.getMaximumPoolSize()
public long getKeepAliveTime(TimeUnit unit)
getKeepAliveTime
in interface ExtendedThreadPool
unit
- the desired time unit of the result
ExtendedThreadPool.setKeepAliveTime(long, java.util.concurrent.TimeUnit)
public void setKeepAliveTime(long time, TimeUnit unit)
setKeepAliveTime
in interface ExtendedThreadPool
time
- the time to wait. A time value of zero will cause
excess threads to terminate immediately after executing tasks.unit
- the time unit of the time argumentExtendedThreadPool.getKeepAliveTime(java.util.concurrent.TimeUnit)
public void setThreadFactory(ThreadFactory threadFactory)
setThreadFactory
in interface ExtendedThreadPool
threadFactory
- the new thread factoryExtendedThreadPool.getThreadFactory()
public ThreadFactory getThreadFactory()
getThreadFactory
in interface ExtendedThreadPool
ExtendedThreadPool.setThreadFactory(java.util.concurrent.ThreadFactory)
public int getPriority()
getPriority
in interface ExtendedThreadPool
public void setPriority(int priority)
setPriority
in interface ExtendedThreadPool
public ByteBufferFactory.ByteBufferType getByteBufferType()
public void setByteBufferType(ByteBufferFactory.ByteBufferType byteBufferType)
public int getInitialByteBufferSize()
public void setInitialByteBufferSize(int initialByteBufferSize)
protected void validateNewPoolSize(int corePoolsize, int maxPoolSize)
protected void beforeExecute(Thread t, Runnable r)
This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke super.beforeExecute at the end of this method.
t
- the thread that will run task r.r
- the task that will be executed.protected void afterExecute(Thread thread, Runnable r, Throwable t)
Note: When actions are enclosed in tasks (such as
FutureTask
) either explicitly or via methods such as
submit, these task objects catch and maintain
computational exceptions, and so they do not cause abrupt
termination, and the internal exceptions are not
passed to this method.
This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke super.afterExecute at the beginning of this method.
thread
- r
- the runnable that has completed.t
- the exception that caused termination, or null if
execution completed normally.protected void onTaskCompletedEvent(Runnable task)
This method will be invoked when a the specified Runnable
has
completed execution.
task
- the unit of work that has completed processingprotected void onWorkerStarted(AbstractThreadPool.Worker worker)
AbstractThreadPool.Worker
, when it's starting
AbstractThreadPool.Worker.run()
method execution, which means, that ThreadPool's
thread is getting active and ready to process tasks.
This method is called from AbstractThreadPool.Worker
's thread.
worker
- protected void onWorkerExit(AbstractThreadPool.Worker worker)
AbstractThreadPool.Worker
, when it's completing
AbstractThreadPool.Worker.run()
method execution, which in most cases means,
that ThreadPool's thread will be released. This method is called from
AbstractThreadPool.Worker
's thread.
worker
- protected void onMaxNumberOfThreadsReached()
protected void onTaskQueued(Runnable task)
task
- protected void onTaskDequeued(Runnable task)
task
- protected void onTaskQueueOverflow()
RejectedExecutionException
public void uncaughtException(Thread thread, Throwable throwable)
uncaughtException
in interface Thread.UncaughtExceptionHandler
protected ThreadFactory getDefaultThreadFactory()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |