Package io.atomix.utils.concurrent
Class SingleThreadContext
java.lang.Object
io.atomix.utils.concurrent.SingleThreadContext
- All Implemented Interfaces:
Scheduler,ThreadContext,CloseableSilently,AutoCloseable,Executor
Single threaded context.
This is a basic ThreadContext implementation that uses a ScheduledExecutorService to schedule events on the context thread.
- Author:
- Jordan Halterman
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ScheduledExecutorServiceprotected static final org.slf4j.Logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionSingleThreadContext(String nameFormat) Creates a new single thread context.protectedSingleThreadContext(ScheduledExecutorService executor, Consumer<Throwable> uncaughtExceptionObserver) Creates a new single thread context.SingleThreadContext(ThreadFactory factory) Creates a new single thread context.SingleThreadContext(ThreadFactory factory, Consumer<Throwable> uncaughtExceptionObserver) Creates a new single thread context. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()By default there are no resources to close.voidprotected static AtomixThreadgetThread(ExecutorService executor) Gets the thread from a single threaded executor service.Schedules a runnable after a delay.Schedules a runnable at a fixed rate.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.atomix.utils.concurrent.ThreadContext
checkThread
-
Field Details
-
LOGGER
protected static final org.slf4j.Logger LOGGER -
executor
-
-
Constructor Details
-
SingleThreadContext
Creates a new single thread context.The provided context name will be passed to
AtomixThreadFactoryand used when instantiating the context thread.- Parameters:
nameFormat- The context nameFormat which will be formatted with a thread number.
-
SingleThreadContext
Creates a new single thread context.- Parameters:
factory- The thread factory.
-
SingleThreadContext
Creates a new single thread context.- Parameters:
factory- The thread factory.uncaughtExceptionObserver- A consumer to observe exceptions thrown by submitted tasks.
-
SingleThreadContext
protected SingleThreadContext(ScheduledExecutorService executor, Consumer<Throwable> uncaughtExceptionObserver) Creates a new single thread context.- Parameters:
executor- The executor on which to schedule events. This must be a single thread scheduled executor.uncaughtExceptionObserver- A consumer to observe exceptions thrown by submitted tasks.
-
-
Method Details
-
getThread
Gets the thread from a single threaded executor service. -
execute
-
schedule
Description copied from interface:SchedulerSchedules a runnable after a delay. -
schedule
Description copied from interface:SchedulerSchedules a runnable at a fixed rate. -
close
public void close()Description copied from interface:ThreadContextBy default there are no resources to close.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseableSilently- Specified by:
closein interfaceScheduler- Specified by:
closein interfaceThreadContext
-