|
||||||||||
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.SyncThreadPool
public class SyncThreadPool
ExecutorService
implementation, which function the similar way as
former Grizzly 1.x Pipeline based thread pools.
The SyncThreadPool is sychronized similar way as Grizzly 1.x Pipeline,
which makes thread pool more accurate when deciding to create or not
additional worker threads.
Nested Class Summary | |
---|---|
protected class |
SyncThreadPool.SyncThreadWorker
|
Nested classes/interfaces inherited from class com.sun.grizzly.util.AbstractThreadPool |
---|
AbstractThreadPool.Worker |
Field Summary | |
---|---|
protected int |
activeThreadsCount
|
protected int |
currentPoolSize
|
protected int |
maxQueuedTasks
|
protected boolean |
running
|
protected Object |
statelock
|
protected int |
threadsCounter
|
protected Map<AbstractThreadPool.Worker,Long> |
workers
|
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 | |
---|---|
SyncThreadPool()
|
|
SyncThreadPool(String name,
int corePoolsize,
int maxPoolSize,
long keepAliveTime,
TimeUnit timeUnit)
|
|
SyncThreadPool(String name,
int corePoolsize,
int maxPoolSize,
long keepAliveTime,
TimeUnit timeUnit,
ThreadFactory threadFactory)
|
|
SyncThreadPool(String name,
int corePoolsize,
int maxPoolSize,
long keepAliveTime,
TimeUnit timeUnit,
ThreadFactory threadFactory,
Queue<Runnable> workQueue,
int maxQueuedTasks)
|
Method Summary | |
---|---|
protected void |
afterExecute(Runnable r,
Throwable t)
Method invoked upon completion of execution of the given Runnable. |
boolean |
awaitTermination(long timeout,
TimeUnit unit)
|
protected void |
beforeExecute(Thread t,
Runnable r)
Method invoked prior to executing the given Runnable in the given thread. |
void |
execute(Runnable task)
|
int |
getActiveCount()
Returns the approximate number of threads that are actively executing tasks. |
long |
getCompletedTaskCount()
Returns the approximate total number of tasks that have completed execution. |
int |
getLargestPoolSize()
Returns the largest number of threads that have ever simultaneously been in the pool. |
int |
getMaxQueuedTasksCount()
|
int |
getPoolSize()
Returns the current number of threads in the pool. |
Queue<Runnable> |
getQueue()
Returns the task queue used by this executor. |
int |
getQueueSize()
Returns the number of tasks, which are currently waiting in the queue. |
int |
getTaskCount()
Returns the approximate total number of tasks that have been scheduled for execution. |
protected void |
injectToStringAttributes(StringBuilder sb)
|
boolean |
isShutdown()
|
boolean |
isTerminated()
|
protected String |
nextThreadId()
|
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. |
void |
setMaxQueuedTasksCount(int maxQueuedTasks)
|
protected void |
setPoolSizes(int corePoolSize,
int maxPoolSize)
|
void |
shutdown()
|
List<Runnable> |
shutdownNow()
|
void |
start()
|
protected void |
startWorker(AbstractThreadPool.Worker wt)
|
void |
stop()
|
String |
toString()
|
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.util.concurrent.ExecutorService |
---|
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit |
Field Detail |
---|
protected int threadsCounter
protected int currentPoolSize
protected int activeThreadsCount
protected int maxQueuedTasks
protected final Object statelock
protected boolean running
protected final Map<AbstractThreadPool.Worker,Long> workers
Constructor Detail |
---|
public SyncThreadPool()
public SyncThreadPool(String name, int corePoolsize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit)
workerprefixname
- corePoolsize
- maxPoolSize
- keepAliveTime
- timeUnit
- TimeUnit
public SyncThreadPool(String name, int corePoolsize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit, ThreadFactory threadFactory)
corePoolsize
- maxPoolSize
- keepAliveTime
- timeUnit
- TimeUnit
threadFactory
- ThreadFactory
public SyncThreadPool(String name, int corePoolsize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit, ThreadFactory threadFactory, Queue<Runnable> workQueue, int maxQueuedTasks)
corePoolsize
- maxPoolSize
- keepAliveTime
- timeUnit
- TimeUnit
threadFactory
- ThreadFactory
workQueue
- BlockingQueue
Method Detail |
---|
public void start()
public void stop()
public void execute(Runnable task)
protected void startWorker(AbstractThreadPool.Worker wt)
public List<Runnable> shutdownNow()
public void shutdown()
public boolean isShutdown()
public boolean isTerminated()
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
InterruptedException
public int getActiveCount()
public int getTaskCount()
public long getCompletedTaskCount()
public int getLargestPoolSize()
public int getPoolSize()
public Queue<Runnable> getQueue()
public int getQueueSize()
public int getMaxQueuedTasksCount()
public void setMaxQueuedTasksCount(int maxQueuedTasks)
protected void setPoolSizes(int corePoolSize, int maxPoolSize)
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.
onWorkerExit
in class AbstractThreadPool
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.
beforeExecute
in class AbstractThreadPool
t
- the thread that will run task r.r
- the task that will be executed.protected void afterExecute(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.
afterExecute
in class AbstractThreadPool
r
- the runnable that has completed.t
- the exception that caused termination, or null if
execution completed normally.protected String nextThreadId()
nextThreadId
in class AbstractThreadPool
public String toString()
toString
in class Object
protected void injectToStringAttributes(StringBuilder sb)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |