Package civitas.celestis.task.lifecycle
Class SchedulerThread
java.lang.Object
java.lang.Thread
civitas.celestis.task.lifecycle.SchedulerThread
- Direct Known Subclasses:
SyncScheduler
A thread which handles the registration and execution of tasks.
This is a strict scheduler, meaning it has no delay between each iteration
of looping through the list of tasks allocated to this thread.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.BuilderPREVIEW, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new scheduler thread.SchedulerThread(String name) Creates a new scheduler thread.SchedulerThread(String name, PrintStream printStream) Creates a new scheduler thread.protectedSchedulerThread(String name, List<Task> tasks, Map<Task, Long> executionTimes, PrintStream printStream) Creates a new scheduler thread. -
Method Summary
Modifier and TypeMethodDescriptionvoidInitializes this module.voidRegisters a task to this scheduler, instructing it to start executing it as soon as possible.voidregisterAsync(Iterable<? extends Task> tasks) Registers multiple tasks asynchronously to this scheduler, instructing it to distribute the tasks across multiple threads however it sees fit.voidregisterSync(Iterable<? extends Task> tasks) Registers multiple tasks synchronously to this scheduler, instructing it to put every provided task into a single thread to ensure sequential execution.voidForcefully stops this module, instructing it to interrupt all threads, and stop operating immediately regardless of its current state.voidunregister(Task task) Unregisters a task from this scheduler, instructing it to stop executing it.voidunregister(Iterable<? extends Task> tasks) Unregisters multiple tasks from this scheduler, instructing it to stop executing every task within the provided iterable object of tasks.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Constructor Details
-
SchedulerThread
public SchedulerThread()Creates a new scheduler thread. -
SchedulerThread
Creates a new scheduler thread.- Parameters:
name- The name of this thread
-
SchedulerThread
Creates a new scheduler thread.- Parameters:
name- The name of this threadprintStream- The print stream to print error messages to
-
SchedulerThread
protected SchedulerThread(@Nonnull String name, @Nonnull List<Task> tasks, @Nonnull Map<Task, Long> executionTimes, @Nonnull PrintStream printStream) Creates a new scheduler thread. If this scheduler shares the list of tasks and/or the map of execution times with another thread, the list and map instances must be thread-safe. They must also be mutable.- Parameters:
name- The name of this threadtasks- The list of tasks allocated to this threadexecutionTimes- The map of recent execution timesprintStream- The print stream to print error messages to
-
-
Method Details
-
register
Registers a task to this scheduler, instructing it to start executing it as soon as possible. -
registerSync
Registers multiple tasks synchronously to this scheduler, instructing it to put every provided task into a single thread to ensure sequential execution.- Specified by:
registerSyncin interfaceScheduler- Parameters:
tasks- The iterable object containing the tasks to register
-
registerAsync
Registers multiple tasks asynchronously to this scheduler, instructing it to distribute the tasks across multiple threads however it sees fit. Sequential execution is not guaranteed, and this is equivalent to iteratively callingScheduler.register(Task)for each task.- Specified by:
registerAsyncin interfaceScheduler- Parameters:
tasks- The iterable object containing the tasks to register
-
unregister
Unregisters a task from this scheduler, instructing it to stop executing it.- Specified by:
unregisterin interfaceScheduler- Parameters:
task- The task to unregister from this scheduler
-
unregister
Unregisters multiple tasks from this scheduler, instructing it to stop executing every task within the provided iterable object of tasks.- Specified by:
unregisterin interfaceScheduler- Parameters:
tasks- The iterable object containing the tasks to unregister
-
initialize
public void initialize()Initializes this module. This is expected to be called before any other method of this module is called.- Specified by:
initializein interfaceModule
-
terminate
public void terminate()Forcefully stops this module, instructing it to interrupt all threads, and stop operating immediately regardless of its current state.
-