public class InstrumentedExecutorService extends Object implements ExecutorService
ExecutorService
that monitors the number of tasks submitted, running,
completed and also keeps a Timer
for the task duration.
It will register the metrics using the given (or auto-generated) name as classifier, e.g: "your-executor-service.submitted", "your-executor-service.running", etc.
Constructor and Description |
---|
InstrumentedExecutorService(ExecutorService delegate,
MetricRegistry registry)
Wraps an
ExecutorService uses an auto-generated default name. |
InstrumentedExecutorService(ExecutorService delegate,
MetricRegistry registry,
String name)
Wraps an
ExecutorService with an explicit name. |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long l,
TimeUnit timeUnit) |
void |
execute(Runnable runnable) |
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks) |
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit) |
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks) |
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit) |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
List<Runnable> |
shutdownNow() |
<T> Future<T> |
submit(Callable<T> task) |
Future<?> |
submit(Runnable runnable) |
<T> Future<T> |
submit(Runnable runnable,
T result) |
public InstrumentedExecutorService(ExecutorService delegate, MetricRegistry registry)
ExecutorService
uses an auto-generated default name.delegate
- ExecutorService
to wrap.registry
- MetricRegistry
that will contain the metrics.public InstrumentedExecutorService(ExecutorService delegate, MetricRegistry registry, String name)
ExecutorService
with an explicit name.delegate
- ExecutorService
to wrap.registry
- MetricRegistry
that will contain the metrics.name
- name for this executor service.public Future<?> submit(Runnable runnable)
submit
in interface ExecutorService
public <T> Future<T> submit(Runnable runnable, T result)
submit
in interface ExecutorService
public <T> Future<T> submit(Callable<T> task)
submit
in interface ExecutorService
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
invokeAll
in interface ExecutorService
InterruptedException
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
invokeAll
in interface ExecutorService
InterruptedException
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws ExecutionException, InterruptedException
invokeAny
in interface ExecutorService
ExecutionException
InterruptedException
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException
invokeAny
in interface ExecutorService
ExecutionException
InterruptedException
TimeoutException
public void shutdown()
shutdown
in interface ExecutorService
public List<Runnable> shutdownNow()
shutdownNow
in interface ExecutorService
public boolean isShutdown()
isShutdown
in interface ExecutorService
public boolean isTerminated()
isTerminated
in interface ExecutorService
public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException
awaitTermination
in interface ExecutorService
InterruptedException
Copyright © 2020. All rights reserved.