Class Scheduler
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.file.Scheduler
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class Scheduler extends java.lang.Object implements java.io.Closeable
A simple scheduler for executing and scheduling tasks in the background. This implementation delegates all background execution to an instance of aScheduledExecutorService
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 intoSafeRunnable
instances. The background thread executing submitted tasks is a deamon thread.
-
-
Constructor Summary
Constructors Constructor Description Scheduler(@Nullable java.lang.String name)
Create a new instance with the givenname
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this scheduler.void
execute(@NotNull java.lang.String name, @NotNull java.lang.Runnable task)
Immediately executetask
.void
scheduleAtFixedRate(@NotNull java.lang.String name, long period, @NotNull java.util.concurrent.TimeUnit unit, @NotNull java.lang.Runnable task)
Runtask
regularly at a given interval.void
scheduleOnce(@NotNull java.lang.String name, long delay, @NotNull java.util.concurrent.TimeUnit unit, @NotNull java.lang.Runnable task)
Runtask
once after some delay.void
scheduleWithFixedDelay(@NotNull java.lang.String name, long delay, @NotNull java.util.concurrent.TimeUnit unit, @NotNull java.lang.Runnable task)
Runtask
regularly after a fixed delay.
-
-
-
Method Detail
-
execute
public void execute(@NotNull @NotNull java.lang.String name, @NotNull @NotNull java.lang.Runnable task)
Immediately executetask
. The background thread's name is set toname
during execution oftask
.- Parameters:
name
-task
-- See Also:
Executor.execute(Runnable)
-
scheduleOnce
public void scheduleOnce(@NotNull @NotNull java.lang.String name, long delay, @NotNull @NotNull java.util.concurrent.TimeUnit unit, @NotNull @NotNull java.lang.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:
ScheduledExecutorService.schedule(Runnable, long, TimeUnit)
-
scheduleAtFixedRate
public void scheduleAtFixedRate(@NotNull @NotNull java.lang.String name, long period, @NotNull @NotNull java.util.concurrent.TimeUnit unit, @NotNull @NotNull java.lang.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:
ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
-
scheduleWithFixedDelay
public void scheduleWithFixedDelay(@NotNull @NotNull java.lang.String name, long delay, @NotNull @NotNull java.util.concurrent.TimeUnit unit, @NotNull @NotNull java.lang.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:
ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)
-
close
public void close()
Close this scheduler.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- See Also:
ExecutorService.shutdown()
-
-