Class Scheduler
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.file.Scheduler
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class Scheduler extends Object implements 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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this scheduler.void
execute(@NotNull String name, @NotNull Runnable task)
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 Detail
-
Scheduler
public Scheduler(@Nullable @Nullable String name)
Create a new instance with the givenname
. The name is used to derive the default name of the background thread from..- Parameters:
name
-
-
-
Method Detail
-
execute
public void execute(@NotNull @NotNull String name, @NotNull @NotNull 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 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:
ScheduledExecutorService.schedule(Runnable, long, TimeUnit)
-
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:
ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
-
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:
ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)
-
close
public void close()
Close this scheduler.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- See Also:
ExecutorService.shutdown()
-
-