public class ThreadPoolExecutorDispatcher extends MultiThreadDispatcher
Dispatcher
that uses a ThreadPoolExecutor
with an unbounded queue to dispatch events.MultiThreadDispatcher.MultiThreadTask
AbstractLifecycleDispatcher.Task
context, DEFAULT_BUFFER_SIZE
Constructor and Description |
---|
ThreadPoolExecutorDispatcher(int poolSize,
int backlog)
Creates a new ThreadPoolExecutorDispatcher with the given poolSize and backlog.
|
ThreadPoolExecutorDispatcher(int backlog,
int poolSize,
ExecutorService executor)
Create a new ThreadPoolTaskExecutor with the given backlog and
ExecutorService . |
ThreadPoolExecutorDispatcher(int poolSize,
int backlog,
String threadName)
Create a new ThreadPoolExecutorDispatcher with the given size, backlog, name, and
RejectedExecutionHandler . |
ThreadPoolExecutorDispatcher(int poolSize,
int backlog,
String threadName,
BlockingQueue<Runnable> workQueue,
RejectedExecutionHandler rejectedExecutionHandler)
Create a new ThreadPoolExecutorDispatcher with the given size, backlog, name, and
RejectedExecutionHandler . |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitAndShutdown(long timeout,
TimeUnit timeUnit)
Block until all submitted tasks have completed, then do a normal
Resource.shutdown() . |
protected void |
execute(AbstractLifecycleDispatcher.Task task) |
void |
execute(Runnable command) |
void |
forceShutdown()
Shutdown this
Resource , forcibly halting any work currently executing and discarding any tasks that
have not yet been executed. |
long |
remainingSlots()
Request the remaining capacity for the underlying shared state structure.
|
void |
shutdown()
Shutdown this active
Resource such that it can no longer be used. |
allocateRecursiveTask, allocateTask, backlogSize, poolSize, scheduleLater, supportsOrdering, tryAllocateTask
alive, awaitAndShutdown, dispatch, getContext, inContext, route, toString, tryDispatch
public ThreadPoolExecutorDispatcher(int poolSize, int backlog)
RejectedExecutionHandler
is created which runs the submitted Runnable
in the calling thread. To change this behavior, specify your own.poolSize
- the pool sizebacklog
- the backlog sizepublic ThreadPoolExecutorDispatcher(int poolSize, int backlog, String threadName)
RejectedExecutionHandler
.poolSize
- the pool sizebacklog
- the backlog sizethreadName
- the name prefix to use when creating threadspublic ThreadPoolExecutorDispatcher(int poolSize, int backlog, String threadName, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler rejectedExecutionHandler)
RejectedExecutionHandler
.poolSize
- the pool sizebacklog
- the backlog sizethreadName
- the name prefix to use when creating threadsrejectedExecutionHandler
- the RejectedExecutionHandler
to use when jobs can't be submitted to the thread poolpublic ThreadPoolExecutorDispatcher(int backlog, int poolSize, ExecutorService executor)
ExecutorService
.backlog
- the task backlogpoolSize
- the number of threadsexecutor
- the executor to use to execute taskspublic boolean awaitAndShutdown(long timeout, TimeUnit timeUnit)
Resource
Resource.shutdown()
.public void shutdown()
Resource
Resource
such that it can no longer be used. If the resource carries any work,
it will wait (but NOT blocking the caller) for all the remaining tasks to perform before closing the resource.shutdown
in interface Resource
shutdown
in class AbstractLifecycleDispatcher
public void forceShutdown()
Resource
Resource
, forcibly halting any work currently executing and discarding any tasks that
have not yet been executed.forceShutdown
in interface Resource
forceShutdown
in class AbstractLifecycleDispatcher
public long remainingSlots()
Dispatcher
RingBufferDispatcher
will return
RingBuffer.remainingCapacity()
.
protected void execute(AbstractLifecycleDispatcher.Task task)
execute
in class AbstractLifecycleDispatcher
public void execute(Runnable command)
execute
in interface Executor
execute
in class AbstractLifecycleDispatcher
Copyright © 2016. All rights reserved.