Package org.apache.zookeeper.server
Class WorkerService
java.lang.Object
org.apache.zookeeper.server.WorkerService
WorkerService is a worker thread pool for running tasks and is implemented
using one or more ExecutorServices. A WorkerService can support assignable
threads, which it does by creating N separate single thread ExecutorServices,
or non-assignable threads, which it does by creating a single N-thread
ExecutorService.
- NIOServerCnxnFactory uses a non-assignable WorkerService because the
socket IO requests are order independent and allowing the
ExecutorService to handle thread assignment gives optimal performance.
- CommitProcessor uses an assignable WorkerService because requests for
a given session must be processed in order.
ExecutorService provides queue management and thread restarting, so it's
useful even with a single thread.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCallers should implement a class extending WorkRequest in order to schedule work with the service. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidjoin(long shutdownTimeoutMS) voidschedule(WorkerService.WorkRequest workRequest) Schedule work to be done.voidschedule(WorkerService.WorkRequest workRequest, long id) Schedule work to be done by the thread assigned to this id.voidstart()voidstop()
-
Constructor Details
-
WorkerService
- Parameters:
name- worker threads are named <name>Thread-##numThreads- number of worker threads (0 - N) If 0, scheduled work is run immediately by the calling thread.useAssignableThreads- whether the worker threads should be individually assignable or not
-
-
Method Details
-
schedule
Schedule work to be done. If a worker thread pool is not being used, work is done directly by this thread. This schedule API is for use with non-assignable WorkerServices. For assignable WorkerServices, will always run on the first thread. -
schedule
Schedule work to be done by the thread assigned to this id. Thread assignment is a single mod operation on the number of threads. If a worker thread pool is not being used, work is done directly by this thread. -
start
public void start() -
stop
public void stop() -
join
public void join(long shutdownTimeoutMS)
-