Package io.atomix.utils.concurrent
Class ThreadPoolContext
- java.lang.Object
-
- io.atomix.utils.concurrent.AbstractThreadContext
-
- io.atomix.utils.concurrent.ThreadPoolContext
-
- All Implemented Interfaces:
Scheduler,ThreadContext,AutoCloseable,Executor
- Direct Known Subclasses:
BlockingAwareThreadPoolContext
public class ThreadPoolContext extends AbstractThreadContext
Thread pool context.This is a special
ThreadContextimplementation that schedules events to be executed on a thread pool. Events executed by this context are guaranteed to be executed on order but may be executed on different threads in the provided thread pool.- Author:
- Jordan Halterman
-
-
Field Summary
Fields Modifier and Type Field Description protected ScheduledExecutorServiceparent
-
Constructor Summary
Constructors Constructor Description ThreadPoolContext(ScheduledExecutorService parent)Creates a new thread pool context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the context.voidexecute(Runnable command)Scheduledschedule(Duration delay, Runnable runnable)Schedules a runnable after a delay.Scheduledschedule(Duration delay, Duration interval, Runnable runnable)Schedules a runnable at a fixed rate.-
Methods inherited from class io.atomix.utils.concurrent.AbstractThreadContext
block, isBlocked, unblock
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.atomix.utils.concurrent.ThreadContext
checkThread, isCurrentContext
-
-
-
-
Field Detail
-
parent
protected final ScheduledExecutorService parent
-
-
Constructor Detail
-
ThreadPoolContext
public ThreadPoolContext(ScheduledExecutorService parent)
Creates a new thread pool context.- Parameters:
parent- The thread pool on which to execute events.
-
-
Method Detail
-
execute
public void execute(Runnable command)
-
schedule
public Scheduled schedule(Duration delay, Runnable runnable)
Description copied from interface:SchedulerSchedules a runnable after a delay.- Parameters:
delay- the delay after which to run the callbackrunnable- the callback to run- Returns:
- the scheduled callback
-
schedule
public Scheduled schedule(Duration delay, Duration interval, Runnable runnable)
Description copied from interface:SchedulerSchedules a runnable at a fixed rate.- Parameters:
delay- the initial delayinterval- the interval at which to run the callbackrunnable- the callback to run- Returns:
- the scheduled callback
-
close
public void close()
Description copied from interface:ThreadContextCloses the context.
-
-