Package io.micrometer.context
Class ContextScheduledExecutorService
java.lang.Object
io.micrometer.context.ContextExecutorService<ScheduledExecutorService>
io.micrometer.context.ContextScheduledExecutorService
- All Implemented Interfaces:
AutoCloseable
,Executor
,ExecutorService
,ScheduledExecutorService
public final class ContextScheduledExecutorService
extends ContextExecutorService<ScheduledExecutorService>
implements ScheduledExecutorService
Wraps a
ScheduledExecutorService
in order to capture context via
ContextSnapshot
when a task is submitted, and propagate context to the task
when it is executed.- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescription<V> ScheduledFuture<V>
scheduleAtFixedRate
(Runnable command, long initialDelay, long period, TimeUnit unit) scheduleWithFixedDelay
(Runnable command, long initialDelay, long delay, TimeUnit unit) static ScheduledExecutorService
wrap
(ScheduledExecutorService service) Deprecated.static ScheduledExecutorService
wrap
(ScheduledExecutorService service, ContextSnapshotFactory contextSnapshotFactory) Wrap the givenScheduledExecutorService
in order to propagate context to any executed task through the givenContextSnapshotFactory
.static ScheduledExecutorService
wrap
(ScheduledExecutorService service, Supplier<ContextSnapshot> supplier) Wrap the givenScheduledExecutorService
in order to propagate context to any executed task through the givenContextSnapshot
supplier.Methods inherited from class io.micrometer.context.ContextExecutorService
awaitTermination, capture, execute, getExecutorService, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit, wrap, wrap, wrap
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, close, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
-
Method Details
-
schedule
- Specified by:
schedule
in interfaceScheduledExecutorService
-
schedule
- Specified by:
schedule
in interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
-
wrap
public static ScheduledExecutorService wrap(ScheduledExecutorService service, ContextSnapshotFactory contextSnapshotFactory) Wrap the givenScheduledExecutorService
in order to propagate context to any executed task through the givenContextSnapshotFactory
.This method only captures ThreadLocal value. To work with other types of contexts, use
wrap(ScheduledExecutorService, Supplier)
.- Parameters:
service
- the executorService to wrapcontextSnapshotFactory
-ContextSnapshotFactory
for capturing aContextSnapshot
at the point when tasks are scheduled- Returns:
ScheduledExecutorService
wrapper- Since:
- 1.1.2
-
wrap
public static ScheduledExecutorService wrap(ScheduledExecutorService service, Supplier<ContextSnapshot> supplier) Wrap the givenScheduledExecutorService
in order to propagate context to any executed task through the givenContextSnapshot
supplier.Typically, a
ContextSnapshotFactory
can be used to supply the snapshot. In the case that only ThreadLocal values are to be captured, thewrap(ScheduledExecutorService, ContextSnapshotFactory)
variant can be used.- Parameters:
service
- the executorService to wrapsupplier
- supplier for capturing aContextSnapshot
at the point when tasks are scheduled- Returns:
ScheduledExecutorService
wrapper
-
wrap
Deprecated.Variant ofwrap(ScheduledExecutorService, Supplier)
that usesContextSnapshot.captureAll(Object...)
to create the context snapshot.- Parameters:
service
- the executorService to wrap- Returns:
ScheduledExecutorService
wrapper
-
wrap(ScheduledExecutorService, Supplier)