public class JobWorkerPool extends Object implements GracefulShutdownHook
| Modifier and Type | Class and Description |
|---|---|
static interface |
JobWorkerPool.Factory |
| Constructor and Description |
|---|
JobWorkerPool(String name,
int poolSize,
GracefulShutdownService gracefulShutdownService,
com.codahale.metrics.MetricRegistry metricRegistry) |
| Modifier and Type | Method and Description |
|---|---|
void |
awaitTermination(long timeout,
TimeUnit unit)
Blocks until all jobs have completed execution after a shutdown request, or the timeout occurs, or the
current thread is interrupted, whichever happens first.
|
void |
doGracefulShutdown()
Execute shutdown tasks for the service that implements this interface.
|
boolean |
execute(Runnable job)
Exeute the given job in the worker pool if there are any free slots.
|
int |
freeSlots()
Returns the number of free slots in the worker pool.
|
boolean |
hasFreeSlots()
Checks if there are free slots in the worker pool
|
void |
shutdown()
Shutdown the worker pool.
|
@Inject public JobWorkerPool(String name, int poolSize, GracefulShutdownService gracefulShutdownService, com.codahale.metrics.MetricRegistry metricRegistry)
public int freeSlots()
public boolean hasFreeSlots()
public boolean execute(Runnable job)
job - the job to executepublic void doGracefulShutdown()
throws Exception
GracefulShutdownHookGracefulShutdownHook must be thread-safe.doGracefulShutdown in interface GracefulShutdownHookExceptionpublic void shutdown()
awaitTermination(long, TimeUnit) to do that.public void awaitTermination(long timeout,
TimeUnit unit)
throws InterruptedException
timeout - the maximum time to waitunit - the time unit of the timeout argumentInterruptedException - if interrupted while waitingCopyright © 2012–2021 Graylog, Inc.. All rights reserved.