com.sun.grizzly.util
Class SyncThreadPool

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by com.sun.grizzly.util.AbstractThreadPool
          extended by com.sun.grizzly.util.SyncThreadPool
All Implemented Interfaces:
ExtendedThreadPool, Thread.UncaughtExceptionHandler, Executor, ExecutorService

public class SyncThreadPool
extends AbstractThreadPool

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.

Author:
Alexey Stashok

Nested Class Summary
protected  class SyncThreadPool.SyncThreadWorker
           
 
Nested classes/interfaces inherited from class com.sun.grizzly.util.AbstractThreadPool
AbstractThreadPool.Worker
 
Field Summary
protected  int maxQueuedTasks
           
 
Fields inherited from class com.sun.grizzly.util.AbstractThreadPool
activeThreadsCount, byteBufferType, corePoolSize, currentPoolSize, DEFAULT_IDLE_THREAD_KEEPALIVE_TIMEOUT, DEFAULT_MAX_TASKS_QUEUED, DEFAULT_MAX_THREAD_COUNT, DEFAULT_MIN_THREAD_COUNT, initialByteBufferSize, keepAliveTime, maxPoolSize, name, poison, priority, probe, running, statelock, threadFactory, workers
 
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)
           
SyncThreadPool(String name, int corePoolsize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit, ThreadFactory threadFactory, Queue<Runnable> workQueue, int maxQueuedTasks, ThreadPoolMonitoringProbe probe)
           
 
Method Summary
protected  void afterExecute(Thread thread, Runnable r, Throwable t)
          Method invoked upon completion of execution of the given Runnable.
 boolean awaitTermination(long timeout, TimeUnit unit)
          
 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.
 boolean isTerminated()
          
protected  void poisonAll()
           
 void setMaxQueuedTasksCount(int maxQueuedTasks)
          
protected  void setPoolSizes(int corePoolSize, int maxPoolSize)
          
 void start()
           
protected  void startWorker(AbstractThreadPool.Worker wt)
          must hold statelock while calling this method.
 void stop()
           
 String toString()
           
 
Methods inherited from class com.sun.grizzly.util.AbstractThreadPool
beforeExecute, drain, getByteBufferType, getCorePoolSize, getDefaultThreadFactory, getInitialByteBufferSize, getKeepAliveTime, getMaximumPoolSize, getName, getPriority, getThreadFactory, isShutdown, nextThreadId, onMaxNumberOfThreadsReached, onTaskCompletedEvent, onTaskDequeued, onTaskQueued, onTaskQueueOverflow, onWorkerExit, onWorkerStarted, setByteBufferType, setCorePoolSize, setInitialByteBufferSize, setKeepAliveTime, setMaximumPoolSize, setName, setPriority, setThreadFactory, shutdown, shutdownNow, 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.util.concurrent.ExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
 

Field Detail

maxQueuedTasks

protected int maxQueuedTasks
Constructor Detail

SyncThreadPool

public SyncThreadPool()

SyncThreadPool

public SyncThreadPool(String name,
                      int corePoolsize,
                      int maxPoolSize,
                      long keepAliveTime,
                      TimeUnit timeUnit)
Parameters:
name -
corePoolsize -
maxPoolSize -
keepAliveTime -
timeUnit - TimeUnit

SyncThreadPool

public SyncThreadPool(String name,
                      int corePoolsize,
                      int maxPoolSize,
                      long keepAliveTime,
                      TimeUnit timeUnit,
                      ThreadFactory threadFactory)
Parameters:
name -
corePoolsize -
maxPoolSize -
keepAliveTime -
timeUnit - TimeUnit
threadFactory - ThreadFactory

SyncThreadPool

public SyncThreadPool(String name,
                      int corePoolsize,
                      int maxPoolSize,
                      long keepAliveTime,
                      TimeUnit timeUnit,
                      ThreadFactory threadFactory,
                      Queue<Runnable> workQueue,
                      int maxQueuedTasks)
Parameters:
name -
corePoolsize -
maxPoolSize -
keepAliveTime -
timeUnit - TimeUnit
threadFactory - ThreadFactory
workQueue - BlockingQueue
maxQueuedTasks -

SyncThreadPool

public SyncThreadPool(String name,
                      int corePoolsize,
                      int maxPoolSize,
                      long keepAliveTime,
                      TimeUnit timeUnit,
                      ThreadFactory threadFactory,
                      Queue<Runnable> workQueue,
                      int maxQueuedTasks,
                      ThreadPoolMonitoringProbe probe)
Parameters:
name -
corePoolsize -
maxPoolSize -
keepAliveTime -
timeUnit -
threadFactory -
workQueue -
maxQueuedTasks -
probe -
Method Detail

start

public void start()

stop

public void stop()

execute

public void execute(Runnable task)


startWorker

protected void startWorker(AbstractThreadPool.Worker wt)
must hold statelock while calling this method.

Overrides:
startWorker in class AbstractThreadPool
Parameters:
wt -

isTerminated

public boolean isTerminated()


awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit unit)
                         throws InterruptedException

Throws:
InterruptedException

getActiveCount

public int getActiveCount()
Returns the approximate number of threads that are actively executing tasks.

Returns:
the number of threads

getTaskCount

public int getTaskCount()
Returns the approximate total number of tasks that have been scheduled for execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.

Returns:
the number of tasks

getCompletedTaskCount

public long getCompletedTaskCount()
Returns the approximate total number of tasks that have completed execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.

Returns:
the number of tasks

getLargestPoolSize

public int getLargestPoolSize()
Returns the largest number of threads that have ever simultaneously been in the pool.

Returns:
the number of threads

getPoolSize

public int getPoolSize()
Returns the current number of threads in the pool.

Returns:
the number of threads

getQueue

public Queue<Runnable> getQueue()
Returns the task queue used by this executor. Access to the task queue is intended primarily for debugging and monitoring. This queue may be in active use. Retrieving the task queue does not prevent queued tasks from executing.

Returns:
the task queue

getQueueSize

public int getQueueSize()
Returns the number of tasks, which are currently waiting in the queue.

Returns:
the number of tasks, which are currently waiting in the queue.

getMaxQueuedTasksCount

public int getMaxQueuedTasksCount()


setMaxQueuedTasksCount

public void setMaxQueuedTasksCount(int maxQueuedTasks)


setPoolSizes

protected void setPoolSizes(int corePoolSize,
                            int maxPoolSize)


afterExecute

protected void afterExecute(Thread thread,
                            Runnable r,
                            Throwable t)
Description copied from class: AbstractThreadPool
Method invoked upon completion of execution of the given Runnable. This method is invoked by the thread that executed the task. If non-null, the Throwable is the uncaught RuntimeException or Error that caused execution to terminate abruptly.

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.

Overrides:
afterExecute in class AbstractThreadPool
r - the runnable that has completed.
t - the exception that caused termination, or null if execution completed normally.

poisonAll

protected void poisonAll()
Overrides:
poisonAll in class AbstractThreadPool

toString

public String toString()
Overrides:
toString in class AbstractThreadPool


Copyright © 2012 Oracle Corporation. All Rights Reserved.