com.sun.grizzly.util
Class DefaultThreadPool

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

public class DefaultThreadPool
extends ThreadPoolExecutor
implements ExecutorService, ExtendedThreadPool, Thread.UncaughtExceptionHandler

Thread Pool implementation, based on ThreadPoolExecutor

Author:
Alexey Stashok

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
 
Field Summary
protected  ByteBufferFactory.ByteBufferType byteBufferType
          The ByteBufferFactory.ByteBufferType
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  int maxTasksCount
           
protected  String name
           
protected  int priority
          Threads priority
protected  AtomicInteger workerThreadCounter
           
 
Constructor Summary
DefaultThreadPool()
           
DefaultThreadPool(int corePoolSize, int maximumPoolSize, int maxTasksCount, long keepAliveTime, TimeUnit unit)
           
 
Method Summary
protected  void afterExecute(Runnable r, Throwable t)
           
protected  void beforeExecute(Thread t, Runnable r)
           
 ByteBufferFactory.ByteBufferType getByteBufferType()
           
 int getInitialByteBufferSize()
           
 int getMaxQueuedTasksCount()
           
 String getName()
           
 int getPriority()
           
 int getQueuedTasksCount()
           
 int getQueueSize()
          Returns the number of tasks, which are currently waiting in the queue.
protected  void injectToStringAttributes(StringBuilder sb)
           
 void setByteBufferType(ByteBufferFactory.ByteBufferType byteBufferType)
           
 void setInitialByteBufferSize(int initialByteBufferSize)
           
 void setMaxQueuedTasksCount(int maxTasksCount)
           
 void setName(String name)
           
 void setPriority(int priority)
           
 void start()
           
 void stop()
           
 String toString()
           
 void uncaughtException(Thread thread, Throwable throwable)
           
 
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated
 
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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
 
Methods inherited from interface java.util.concurrent.Executor
execute
 
Methods inherited from interface com.sun.grizzly.util.ExtendedThreadPool
getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getTaskCount, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize
 

Field Detail

DEFAULT_MIN_THREAD_COUNT

public static int DEFAULT_MIN_THREAD_COUNT

DEFAULT_MAX_THREAD_COUNT

public static int DEFAULT_MAX_THREAD_COUNT

DEFAULT_MAX_TASKS_QUEUED

public static int DEFAULT_MAX_TASKS_QUEUED

DEFAULT_IDLE_THREAD_KEEPALIVE_TIMEOUT

public static int DEFAULT_IDLE_THREAD_KEEPALIVE_TIMEOUT

name

protected String name

maxTasksCount

protected int maxTasksCount

workerThreadCounter

protected AtomicInteger workerThreadCounter

priority

protected int priority
Threads priority


initialByteBufferSize

protected int initialByteBufferSize
The initial ByteBuffer size for newly created WorkerThread instances


byteBufferType

protected ByteBufferFactory.ByteBufferType byteBufferType
The ByteBufferFactory.ByteBufferType

Constructor Detail

DefaultThreadPool

public DefaultThreadPool()

DefaultThreadPool

public DefaultThreadPool(int corePoolSize,
                         int maximumPoolSize,
                         int maxTasksCount,
                         long keepAliveTime,
                         TimeUnit unit)
Method Detail

getQueuedTasksCount

public int getQueuedTasksCount()

getMaxQueuedTasksCount

public int getMaxQueuedTasksCount()
Specified by:
getMaxQueuedTasksCount in interface ExtendedThreadPool

setMaxQueuedTasksCount

public void setMaxQueuedTasksCount(int maxTasksCount)
Specified by:
setMaxQueuedTasksCount in interface ExtendedThreadPool

getName

public String getName()
Specified by:
getName in interface ExtendedThreadPool

setName

public void setName(String name)
Specified by:
setName in interface ExtendedThreadPool

getPriority

public int getPriority()

setPriority

public void setPriority(int priority)

getQueueSize

public int getQueueSize()
Description copied from interface: ExtendedThreadPool
Returns the number of tasks, which are currently waiting in the queue.

Specified by:
getQueueSize in interface ExtendedThreadPool
Returns:
the number of tasks, which are currently waiting in the queue.

getByteBufferType

public ByteBufferFactory.ByteBufferType getByteBufferType()

setByteBufferType

public void setByteBufferType(ByteBufferFactory.ByteBufferType byteBufferType)

getInitialByteBufferSize

public int getInitialByteBufferSize()

setInitialByteBufferSize

public void setInitialByteBufferSize(int initialByteBufferSize)

start

public void start()

stop

public void stop()

uncaughtException

public void uncaughtException(Thread thread,
                              Throwable throwable)
Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler

beforeExecute

protected void beforeExecute(Thread t,
                             Runnable r)
Overrides:
beforeExecute in class ThreadPoolExecutor

afterExecute

protected void afterExecute(Runnable r,
                            Throwable t)
Overrides:
afterExecute in class ThreadPoolExecutor

toString

public String toString()
Overrides:
toString in class Object

injectToStringAttributes

protected void injectToStringAttributes(StringBuilder sb)


Copyright © 2008 SUN Microsystems. All Rights Reserved.