Class Scheduler
java.lang.Object
org.apache.jackrabbit.oak.segment.file.Scheduler
- All Implemented Interfaces:
Closeable,AutoCloseable
A simple scheduler for executing and scheduling tasks in the background.
This implementation delegates all background execution to an instance
of a
ScheduledExecutorService with core pool size 1. The behaviour
of this underlying scheduler service determines the semantics of the methods
in this class. Namely: Execution of background tasks never overlaps and is
FIFO for tasks scheduled for the same time.
In addition all tasks scheduled through methods of this class are automatically
wrapped into SafeRunnable instances. The background thread executing
submitted tasks is a deamon thread.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this scheduler.voidImmediately executetask.voidscheduleAtFixedRate(@NotNull String name, long period, @NotNull TimeUnit unit, @NotNull Runnable task) Runtaskregularly at a given interval.voidscheduleOnce(@NotNull String name, long delay, @NotNull TimeUnit unit, @NotNull Runnable task) Runtaskonce after some delay.voidscheduleWithFixedDelay(@NotNull String name, long delay, @NotNull TimeUnit unit, @NotNull Runnable task) Runtaskregularly after a fixed delay.
-
Constructor Details
-
Scheduler
Create a new instance with the givenname. The name is used to derive the default name of the background thread from..- Parameters:
name-
-
-
Method Details
-
execute
Immediately executetask. The background thread's name is set tonameduring execution oftask.- Parameters:
name-task-- See Also:
-
scheduleOnce
public void scheduleOnce(@NotNull @NotNull String name, long delay, @NotNull @NotNull TimeUnit unit, @NotNull @NotNull Runnable task) Runtaskonce after some delay. The background thread's name is set tonameduring execution oftask.- Parameters:
name-delay-unit-task-- See Also:
-
scheduleAtFixedRate
public void scheduleAtFixedRate(@NotNull @NotNull String name, long period, @NotNull @NotNull TimeUnit unit, @NotNull @NotNull Runnable task) Runtaskregularly at a given interval. The background thread's name is set tonameduring execution oftask.- Parameters:
name-period-unit-task-- See Also:
-
scheduleWithFixedDelay
public void scheduleWithFixedDelay(@NotNull @NotNull String name, long delay, @NotNull @NotNull TimeUnit unit, @NotNull @NotNull Runnable task) Runtaskregularly after a fixed delay. The background thread's name is set tonameduring execution oftask.- Parameters:
name-delay-unit-task-- See Also:
-
close
public void close()Close this scheduler.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- See Also:
-