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 TypeMethodDescriptionvoid
close()
Close this scheduler.void
Immediately executetask
.void
scheduleAtFixedRate
(@NotNull String name, long period, @NotNull TimeUnit unit, @NotNull Runnable task) Runtask
regularly at a given interval.void
scheduleOnce
(@NotNull String name, long delay, @NotNull TimeUnit unit, @NotNull Runnable task) Runtask
once after some delay.void
scheduleWithFixedDelay
(@NotNull String name, long delay, @NotNull TimeUnit unit, @NotNull Runnable task) Runtask
regularly 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 toname
during 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) Runtask
once after some delay. The background thread's name is set toname
during 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) Runtask
regularly at a given interval. The background thread's name is set toname
during 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) Runtask
regularly after a fixed delay. The background thread's name is set toname
during execution oftask
.- Parameters:
name
-delay
-unit
-task
-- See Also:
-
close
public void close()Close this scheduler.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- See Also:
-