Top Fields Constructors Methods
org.apache.hc.core5.http.impl.bootstrap

pack-priv Class WorkerPoolExecutor

extends ThreadPoolExecutor
Class Inheritance
Imports
java.util.HashSet, .Map, .Set, java.util.concurrent.BlockingQueue, .ConcurrentHashMap, .ThreadFactory, .ThreadPoolExecutor, .TimeUnit

Field Summary

Modifier and TypeField and Description
private final Map<Worker, Boolean>

Constructor Summary

AccessConstructor and Description
public
WorkerPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, final BlockingQueue<Runnable> workQueue, final ThreadFactory threadFactory)

Method Summary

Modifier and TypeMethod and Description
protected void
afterExecute(final Runnable
the runnable that has completed
r
,
final Throwable
the exception that caused termination, or null if execution completed normally
t
)

Overrides java.util.concurrent.ThreadPoolExecutor.afterExecute.

Method invoked upon completion of execution of the given Runnable.
protected void
beforeExecute(final Thread
the thread that will run task r
t
,
final Runnable
the task that will be executed
r
)

Overrides java.util.concurrent.ThreadPoolExecutor.beforeExecute.

Method invoked prior to executing the given Runnable in the given thread.
public Set<Worker>
Inherited from java.util.concurrent.ThreadPoolExecutor:
allowCoreThreadTimeOutallowsCoreThreadTimeOutawaitTerminationexecutefinalizegetActiveCountgetCompletedTaskCountgetCorePoolSizegetKeepAliveTimegetLargestPoolSizegetMaximumPoolSizegetPoolSizegetQueuegetRejectedExecutionHandlergetTaskCountgetThreadFactoryisShutdownisTerminatedisTerminatingprestartAllCoreThreadsprestartCoreThreadpurgeremovesetCorePoolSizesetKeepAliveTimesetMaximumPoolSizesetRejectedExecutionHandlersetThreadFactoryshutdownshutdownNowterminatedtoString

Field Detail

workerSetback to summary
private final Map<Worker, Boolean> workerSet

Constructor Detail

WorkerPoolExecutorback to summary
public WorkerPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, final BlockingQueue<Runnable> workQueue, final ThreadFactory threadFactory)

Method Detail

afterExecuteback to summary
protected void afterExecute(final Runnable r, final Throwable t)

Overrides java.util.concurrent.ThreadPoolExecutor.afterExecute.

Doc from java.util.concurrent.ThreadPoolExecutor.afterExecute.

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.

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.

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. If you would like to trap both kinds of failures in this method, you can further probe for such cases, as in this sample subclass that prints either the direct cause or the underlying exception if a task has been aborted:

 class ExtendedExecutor extends ThreadPoolExecutor {
  // ...
  protected void afterExecute(Runnable r, Throwable t) {
    super.afterExecute(r, t);
    if (t == null
        && r instanceof Future<?>
        && ((Future<?>)r).isDone()) {
      try {
        Object result = ((Future<?>) r).get();
      } catch (CancellationException ce) {
        t = ce;
      } catch (ExecutionException ee) {
        t = ee.getCause();
      } catch (InterruptedException ie) {
        // ignore/reset
        Thread.currentThread().interrupt();
      }
    }
    if (t != null)
      System.out.println(t);
  }
}
Parameters
r:Runnable

the runnable that has completed

t:Throwable

the exception that caused termination, or null if execution completed normally

Annotations
@Override
beforeExecuteback to summary
protected void beforeExecute(final Thread t, final Runnable r)

Overrides java.util.concurrent.ThreadPoolExecutor.beforeExecute.

Doc from java.util.concurrent.ThreadPoolExecutor.beforeExecute.

Method invoked prior to executing the given Runnable in the given thread. This method is invoked by thread t that will execute task r, and may be used to re-initialize ThreadLocals, or to perform logging.

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.

Parameters
t:Thread

the thread that will run task r

r:Runnable

the task that will be executed

Annotations
@Override
getWorkersback to summary
public Set<Worker> getWorkers()