|
||||||||||
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
com.sun.grizzly.util.FixedThreadPool
com.sun.grizzly.util.DefaultThreadPool
public class DefaultThreadPool
ExecutorService
implementation, which function the similar way as
former Grizzly 1.x Pipeline based thread pools.
Unlike DefaultThreadPool
, this thread pool, if there are no free
worker threads available, prefers to create new worker thread, up-to maximum,
to process new task. And only if max threads count is reached - this
thread pool will start to add tasks to queue. Where DefaultThreadPool
first tries to add new task to queue, and only if task queue reaches its
maximum - creates new worker thread.
corethreads are prestarted.
maxPoolSize is runtime configurable.
Designed around the use of lockfree queue.
less performant then FixedThreadPool
due to keeping track
of queue size to know when to spawn a worker or not, creating a chokepoint between producers and consumers
in the form of looping around compareAndSet inside AtomicInteger
to update the queue size for each put and get of a task .
for short lived tasks at saturation throughput this overhead can be substantial on some platforms.
by default: WorkerThreadImpl
is used,
LinkedTransferQueue
is used as workQueue , this means that its FIFO per producer.
Nested Class Summary | |
---|---|
protected class |
DefaultThreadPool.DefaultThreadWorker
|
Nested classes/interfaces inherited from class com.sun.grizzly.util.FixedThreadPool |
---|
FixedThreadPool.BasicWorker |
Nested classes/interfaces inherited from class com.sun.grizzly.util.AbstractThreadPool |
---|
AbstractThreadPool.Worker |
Field Summary | |
---|---|
protected AtomicInteger |
workerThreadCounter
|
Fields inherited from class com.sun.grizzly.util.FixedThreadPool |
---|
aliveworkerCount, approximateRunningWorkerCount, running, statelock, workers, workQueue |
Fields inherited from class com.sun.grizzly.util.AbstractThreadPool |
---|
byteBufferType, corePoolSize, DEFAULT_IDLE_THREAD_KEEPALIVE_TIMEOUT, DEFAULT_MAX_TASKS_QUEUED, DEFAULT_MAX_THREAD_COUNT, DEFAULT_MIN_THREAD_COUNT, initialByteBufferSize, keepAliveTime, maxPoolSize, name, poison, priority, threadFactory |
Constructor Summary | |
---|---|
DefaultThreadPool()
|
|
DefaultThreadPool(String name,
int corePoolsize,
int maxPoolSize,
long keepAliveTime,
TimeUnit timeUnit)
|
|
DefaultThreadPool(String name,
int corePoolsize,
int maxPoolSize,
long keepAliveTime,
TimeUnit timeUnit,
ThreadFactory threadFactory)
|
|
DefaultThreadPool(String name,
int corePoolsize,
int maxPoolSize,
long keepAliveTime,
TimeUnit timeUnit,
ThreadFactory threadFactory,
BlockingQueue<Runnable> workQueue)
|
Method Summary | |
---|---|
protected void |
afterExecute(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. |
void |
execute(Runnable task)
|
int |
getCorePoolSize()
Returns the core number of threads. |
int |
getMaximumPoolSize()
Returns the maximum allowed number of threads. |
int |
getQueueSize()
Runs at O(n) time with default Impl. |
protected void |
injectToStringAttributes(StringBuilder sb)
|
protected String |
nextThreadId()
|
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. |
void |
setCorePoolSize(int corePoolSize)
Sets the core number of threads. |
void |
setMaximumPoolSize(int maxPoolSize)
Sets the maximum allowed number of threads. |
protected void |
setPoolSizes(int corePoolSize,
int maxPoolSize)
|
void |
start()
|
void |
stop()
|
String |
toString()
|
Methods inherited from class com.sun.grizzly.util.FixedThreadPool |
---|
awaitTermination, getActiveCount, getCompletedTaskCount, getLargestPoolSize, getMaxQueuedTasksCount, getPoolSize, getQueue, getTaskCount, isShutdown, isTerminated, onWorkerExit, setMaxQueuedTasksCount, shutdown, shutdownNow, startWorker |
Methods inherited from class com.sun.grizzly.util.AbstractThreadPool |
---|
getByteBufferType, getInitialByteBufferSize, getKeepAliveTime, getName, getPriority, getThreadFactory, onMaxNumberOfThreadsReached, onTaskQueueOverflow, onWorkerStarted, setByteBufferType, setInitialByteBufferSize, setKeepAliveTime, setName, setPriority, setThreadFactory, uncaughtException, validateNewPoolSize |
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 java.lang.Thread.UncaughtExceptionHandler |
---|
uncaughtException |
Methods inherited from interface java.util.concurrent.ExecutorService |
---|
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit |
Field Detail |
---|
protected final AtomicInteger workerThreadCounter
Constructor Detail |
---|
public DefaultThreadPool()
public DefaultThreadPool(String name, int corePoolsize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit)
workerprefixname
- corePoolsize
- maxPoolSize
- keepAliveTime
- timeUnit
- TimeUnit
public DefaultThreadPool(String name, int corePoolsize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit, ThreadFactory threadFactory)
corePoolsize
- maxPoolSize
- keepAliveTime
- timeUnit
- TimeUnit
threadFactory
- ThreadFactory
public DefaultThreadPool(String name, int corePoolsize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit, ThreadFactory threadFactory, BlockingQueue<Runnable> workQueue)
corePoolsize
- maxPoolSize
- keepAliveTime
- timeUnit
- TimeUnit
threadFactory
- ThreadFactory
workQueue
- BlockingQueue
Method Detail |
---|
public void execute(Runnable task)
execute
in interface Executor
execute
in class FixedThreadPool
public void start()
public void stop()
protected void onTaskQueued(Runnable task)
AbstractThreadPool
onTaskQueued
in class AbstractThreadPool
protected void onTaskDequeued(Runnable task)
AbstractThreadPool
onTaskDequeued
in class AbstractThreadPool
public int getQueueSize()
FixedThreadPool
getQueueSize
in interface ExtendedThreadPool
getQueueSize
in class FixedThreadPool
protected void setPoolSizes(int corePoolSize, int maxPoolSize)
public void setCorePoolSize(int corePoolSize)
FixedThreadPool
setCorePoolSize
in interface ExtendedThreadPool
setCorePoolSize
in class FixedThreadPool
corePoolSize
- the new core sizeExtendedThreadPool.getCorePoolSize()
public int getCorePoolSize()
AbstractThreadPool
getCorePoolSize
in interface ExtendedThreadPool
getCorePoolSize
in class AbstractThreadPool
ExtendedThreadPool.setCorePoolSize(int)
public void setMaximumPoolSize(int maxPoolSize)
FixedThreadPool
setMaximumPoolSize
in interface ExtendedThreadPool
setMaximumPoolSize
in class FixedThreadPool
maxPoolSize
- ExtendedThreadPool.getMaximumPoolSize()
public int getMaximumPoolSize()
AbstractThreadPool
getMaximumPoolSize
in interface ExtendedThreadPool
getMaximumPoolSize
in class AbstractThreadPool
ExtendedThreadPool.setMaximumPoolSize(int)
protected String nextThreadId()
FixedThreadPool
nextThreadId
in class FixedThreadPool
public String toString()
toString
in class Object
protected void injectToStringAttributes(StringBuilder sb)
protected void beforeExecute(Thread t, Runnable r)
FixedThreadPool
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.
beforeExecute
in class FixedThreadPool
t
- the thread that will run task r.r
- the task that will be executed.protected void afterExecute(Runnable r, Throwable t)
FixedThreadPool
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.
afterExecute
in class FixedThreadPool
r
- the runnable that has completed.t
- the exception that caused termination, or null if
execution completed normally.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |