API Overview API Index Package Overview Direct link to this page
JDK 1.6
  java.util.concurrent. ThreadPoolExecutor View Source
Author(s)
Doug Lea
Since
1.5
Version
Serial
Hierarchy
 Object
      AbstractExecutorService
          ThreadPoolExecutor
Implements
Subclasses
Description
public class ThreadPoolExecutor
  An ExecutorService that executes each submitted task using one of possibly several pooled threads, normally configured using Executors factory methods.
See also:   
Constructors
public ThreadPoolExecutor (int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue)
  Creates a new ThreadPoolExecutor with the given initial parameters and default thread factory and rejected execution handler.
public ThreadPoolExecutor (int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler)
  Creates a new ThreadPoolExecutor with the given initial parameters and default thread factory.
public ThreadPoolExecutor (int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory)
  Creates a new ThreadPoolExecutor with the given initial parameters and default rejected execution handler.
public ThreadPoolExecutor (int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
  Creates a new ThreadPoolExecutor with the given initial parameters.
Methods
Hide/Show inherited methods
protected void afterExecute (Runnable r, Throwable t)
  Method invoked upon completion of execution of the given Runnable.
public void allowCoreThreadTimeOut (boolean value)
  Sets the policy governing whether core threads may time out and terminate if no tasks arrive within the keep-alive time, being replaced if needed when new tasks arrive.
public boolean allowsCoreThreadTimeOut ()
  Returns true if this pool allows core threads to time out and terminate if no tasks arrive within the keepAlive time, being replaced if needed when new tasks arrive.
public boolean awaitTermination (long timeout, TimeUnit unit) throws InterruptedException
protected void beforeExecute (Thread t, Runnable r)
  Method invoked prior to executing the given Runnable in the given thread.
public void execute (Runnable command)
  Executes the given task sometime in the future.
protected void finalize ()
Invokes shutdown when this executor is no longer referenced.
public int getActiveCount ()
  Returns the approximate number of threads that are actively executing tasks.
public long getCompletedTaskCount ()
  Returns the approximate total number of tasks that have completed execution.
public int getCorePoolSize ()
  Returns the core number of threads.
public long getKeepAliveTime (TimeUnit unit)
  Returns the thread keep-alive time, which is the amount of time that threads in excess of the core pool size may remain idle before being terminated.
public int getLargestPoolSize ()
  Returns the largest number of threads that have ever simultaneously been in the pool.
public int getMaximumPoolSize ()
  Returns the maximum allowed number of threads.
public int getPoolSize ()
  Returns the current number of threads in the pool.
public BlockingQueue<Runnable> getQueue ()
  Returns the task queue used by this executor.
public RejectedExecutionHandler getRejectedExecutionHandler ()
  Returns the current handler for unexecutable tasks.
pack-private Runnable getTask ()
  Gets the next task for a worker thread to run.
public long getTaskCount ()
  Returns the approximate total number of tasks that have ever been scheduled for execution.
public ThreadFactory getThreadFactory ()
  Returns the thread factory used to create new threads.
pack-private void interruptIdleWorkers ()
  Wakes up all threads that might be waiting for tasks so they can check for termination.
public List<Future< T>> invokeAll (Collection<Callable> tasks) throws InterruptedException [Inherited From AbstractExecutorService]
public List<Future< T>> invokeAll (Collection<Callable> tasks, long timeout, TimeUnit unit) throws InterruptedException [Inherited From AbstractExecutorService]
public T invokeAny (Collection<Callable> tasks) throws InterruptedException ExecutionException [Inherited From AbstractExecutorService]
public T invokeAny (Collection<Callable> tasks, long timeout, TimeUnit unit) throws InterruptedException ExecutionException TimeoutException [Inherited From AbstractExecutorService]
public boolean isShutdown ()
public boolean isTerminated ()
public boolean isTerminating ()
  Returns true if this executor is in the process of terminating after shutdown or shutdownNow but has not completely terminated.
protected RunnableFuture< T> newTaskFor (Callable< T> callable) [Inherited From AbstractExecutorService]
  Returns a RunnableFuture for the given callable task.
protected RunnableFuture< T> newTaskFor (Runnable runnable, T value) [Inherited From AbstractExecutorService]
  Returns a RunnableFuture for the given runnable and default value.
public int prestartAllCoreThreads ()
  Starts all core threads, causing them to idly wait for work.
public boolean prestartCoreThread ()
  Starts a core thread, causing it to idly wait for work.
public void purge ()
  Tries to remove from the work queue all Future tasks that have been cancelled.
pack-private void reject (Runnable command)
Invokes the rejected execution handler for the given command.
public boolean remove (Runnable task)
  Removes this task from the executor's internal queue if it is present, thus causing it not to be run if it has not already started.
public void setCorePoolSize (int corePoolSize)
  Sets the core number of threads.
public void setKeepAliveTime (long time, TimeUnit unit)
  Sets the time limit for which threads may remain idle before being terminated.
public void setMaximumPoolSize (int maximumPoolSize)
  Sets the maximum allowed number of threads.
public void setRejectedExecutionHandler (RejectedExecutionHandler handler)
  Sets a new handler for unexecutable tasks.
public void setThreadFactory (ThreadFactory threadFactory)
  Sets the thread factory used to create new threads.
public void shutdown ()
  Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
public List<Runnable> shutdownNow ()
  Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
public Future< T> submit (Callable< T> task) [Inherited From AbstractExecutorService]
public Future<Object> submit (Runnable task) [Inherited From AbstractExecutorService]
public Future< T> submit (Runnable task, T result) [Inherited From AbstractExecutorService]
protected void terminated ()
  Method invoked when the Executor has terminated.
pack-private void workerDone (Worker w)
  Performs bookkeeping for an exiting worker thread.
Fields
Hide/Show inherited fields
pack-privatefinalstatic int RUNNING = "0"
pack-privatevolatile int runState
  runState provides the main lifecyle control, taking on values: RUNNING: Accept new tasks and process queued tasks SHUTDOWN: Don't accept new tasks, but process queued tasks STOP: Don't accept new tasks, don't process queued tasks, and interrupt in-progress tasks TERMINATED: Same as STOP, plus all threads have terminated The numerical order among these values matters, to allow ordered comparisons.
pack-privatefinalstatic int SHUTDOWN = "1"
pack-privatefinalstatic int STOP = "2"
pack-privatefinalstatic int TERMINATED = "3"
Nested Classes
  ThreadPoolExecutor.CallerRunsPolicy
A handler for rejected tasks that runs the rejected task directly in the calling thread of the execute method, unless the executor has been shut down, in which case the task is discarded.
  ThreadPoolExecutor.AbortPolicy
A handler for rejected tasks that throws a RejectedExecutionException.
  ThreadPoolExecutor.DiscardPolicy
A handler for rejected tasks that silently discards the rejected task.
  ThreadPoolExecutor.DiscardOldestPolicy
A handler for rejected tasks that discards the oldest unhandled request and then retries execute, unless the executor is shut down, in which case the task is discarded.
Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar