Top Description Constructors Methods
io.micrometer.context

public final Class ContextScheduledExecutorService

extends ContextExecutorService<ScheduledExecutorService>
implements ScheduledExecutorService
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ScheduledExecutorService, java.util.concurrent.ExecutorService, java.lang.AutoCloseable, java.util.concurrent.Executor
Imports
java.util.concurrent.Callable, .ScheduledExecutorService, .ScheduledFuture, .TimeUnit, java.util.function.Supplier

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.
Authors
Marcin Grzejszczak, Rossen Stoyanchev
Since
1.0.0

Constructor Summary

AccessConstructor and Description
private
ContextScheduledExecutorService(ScheduledExecutorService
the ScheduledExecutorService to delegate to
service
,
Supplier<ContextSnapshot>
supplier of the ContextSnapshot - instruction on who to retrieve ContextSnapshot when tasks are scheduled
snapshotSupplier
)

Create an instance

Method Summary

Modifier and TypeMethod and Description
public ScheduledFuture<?>
schedule(Runnable
the task to execute
command
,
long
the time from now to delay execution
delay
,
TimeUnit
the time unit of the delay parameter
unit
)

Implements java.util.concurrent.ScheduledExecutorService.schedule.

Submits a one-shot task that becomes enabled after the given delay.
public <V> ScheduledFuture<V>
schedule(Callable<V>
the function to execute
callable
,
long
the time from now to delay execution
delay
,
TimeUnit
the time unit of the delay parameter
unit
)

Implements java.util.concurrent.ScheduledExecutorService.schedule.

Submits a value-returning one-shot task that becomes enabled after the given delay.
public ScheduledFuture<?>
scheduleAtFixedRate(Runnable
the task to execute
command
,
long
the time to delay first execution
initialDelay
,
long
the period between successive executions
period
,
TimeUnit
the time unit of the initialDelay and period parameters
unit
)

Implements java.util.concurrent.ScheduledExecutorService.scheduleAtFixedRate.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after initialDelay, then initialDelay + period, then initialDelay + 2 * period, and so on.
public ScheduledFuture<?>
scheduleWithFixedDelay(Runnable
the task to execute
command
,
long
the time to delay first execution
initialDelay
,
long
the delay between the termination of one execution and the commencement of the next
delay
,
TimeUnit
the time unit of the initialDelay and delay parameters
unit
)

Implements java.util.concurrent.ScheduledExecutorService.scheduleWithFixedDelay.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
public static ScheduledExecutorService
wrap(ScheduledExecutorService
the executorService to wrap
service
,
Supplier<ContextSnapshot>
supplier for capturing a ContextSnapshot at the point when tasks are scheduled
supplier
)

Wrap the given ScheduledExecutorService in order to propagate context to any executed task through the given ContextSnapshot supplier.

public static ScheduledExecutorService
Inherited from io.micrometer.context.ContextExecutorService:
awaitTerminationcaptureexecutegetExecutorServiceinvokeAllinvokeAllinvokeAnyinvokeAnyisShutdownisTerminatedshutdownshutdownNowsubmitsubmitsubmitwrapwrap

Constructor Detail

ContextScheduledExecutorServiceback to summary
private ContextScheduledExecutorService(ScheduledExecutorService service, Supplier<ContextSnapshot> snapshotSupplier)

Create an instance

Parameters
service:ScheduledExecutorService

the ScheduledExecutorService to delegate to

snapshotSupplier:Supplier<ContextSnapshot>

supplier of the ContextSnapshot - instruction on who to retrieve ContextSnapshot when tasks are scheduled

Method Detail

scheduleback to summary
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)

Implements java.util.concurrent.ScheduledExecutorService.schedule.

Doc from java.util.concurrent.ScheduledExecutorService.schedule.

Submits a one-shot task that becomes enabled after the given delay.

Parameters
command:Runnable

the task to execute

delay:long

the time from now to delay execution

unit:TimeUnit

the time unit of the delay parameter

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion

Annotations
@Override
scheduleback to summary
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)

Implements java.util.concurrent.ScheduledExecutorService.schedule.

Doc from java.util.concurrent.ScheduledExecutorService.schedule.

Submits a value-returning one-shot task that becomes enabled after the given delay.

Parameters
<V>
the type of the callable's result
callable:Callable<V>

the function to execute

delay:long

the time from now to delay execution

unit:TimeUnit

the time unit of the delay parameter

Returns:ScheduledFuture<V>

a ScheduledFuture that can be used to extract result or cancel

Annotations
@Override
scheduleAtFixedRateback to summary
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)

Implements java.util.concurrent.ScheduledExecutorService.scheduleAtFixedRate.

Doc from java.util.concurrent.ScheduledExecutorService.scheduleAtFixedRate.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after initialDelay, then initialDelay + period, then initialDelay + 2 * period, and so on.

The sequence of task executions continues indefinitely until one of the following exceptional completions occur:

  • The task is explicitly cancelled via the returned future.
  • The executor terminates, also resulting in task cancellation.
  • An execution of the task throws an exception. In this case calling get on the returned future will throw ExecutionException, holding the exception as its cause.
Subsequent executions are suppressed. Subsequent calls to isDone() on the returned future will return true.

If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

Parameters
command:Runnable

the task to execute

initialDelay:long

the time to delay first execution

period:long

the period between successive executions

unit:TimeUnit

the time unit of the initialDelay and period parameters

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the series of repeated tasks. The future's get() method will never return normally, and will throw an exception upon task cancellation or abnormal termination of a task execution.

Annotations
@Override
scheduleWithFixedDelayback to summary
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)

Implements java.util.concurrent.ScheduledExecutorService.scheduleWithFixedDelay.

Doc from java.util.concurrent.ScheduledExecutorService.scheduleWithFixedDelay.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.

The sequence of task executions continues indefinitely until one of the following exceptional completions occur:

  • The task is explicitly cancelled via the returned future.
  • The executor terminates, also resulting in task cancellation.
  • An execution of the task throws an exception. In this case calling get on the returned future will throw ExecutionException, holding the exception as its cause.
Subsequent executions are suppressed. Subsequent calls to isDone() on the returned future will return true.
Parameters
command:Runnable

the task to execute

initialDelay:long

the time to delay first execution

delay:long

the delay between the termination of one execution and the commencement of the next

unit:TimeUnit

the time unit of the initialDelay and delay parameters

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the series of repeated tasks. The future's get() method will never return normally, and will throw an exception upon task cancellation or abnormal termination of a task execution.

Annotations
@Override
wrapback to summary
public static ScheduledExecutorService wrap(ScheduledExecutorService service, Supplier<ContextSnapshot> supplier)

Wrap the given ScheduledExecutorService in order to propagate context to any executed task through the given ContextSnapshot supplier.

Parameters
service:ScheduledExecutorService

the executorService to wrap

supplier:Supplier<ContextSnapshot>

supplier for capturing a ContextSnapshot at the point when tasks are scheduled

wrapback to summary
public static ScheduledExecutorService wrap(ScheduledExecutorService service)

Variant of wrap(ScheduledExecutorService, Supplier) that uses ContextSnapshot#captureAll(Object...) to create the context snapshot.

Parameters
service:ScheduledExecutorService

the executorService to wrap

Annotations
@Deprecated