Package com.jozufozu.flywheel.impl.task
Class SerialTaskExecutor
java.lang.Object
com.jozufozu.flywheel.impl.task.SerialTaskExecutor
- All Implemented Interfaces:
TaskExecutor,Executor
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanCheck whether the current thread is this task executor's main thread.voidscheduleForMainThread(Runnable runnable) Schedule a task to be run on the main thread.voidWait for all running tasks to finish.booleansyncUntil(BooleanSupplier cond) Wait for running tasks, until the given condition is met (BooleanSupplier.getAsBoolean()returnstrue).booleansyncWhile(BooleanSupplier cond) Wait for running tasks, so long as the given condition is met (BooleanSupplier.getAsBoolean()returnstrue).intCheck for the number of threads this executor uses.
-
Field Details
-
INSTANCE
-
-
Method Details
-
execute
-
scheduleForMainThread
Description copied from interface:TaskExecutorSchedule a task to be run on the main thread.
This method may be called from any thread (including the main thread), but the runnable will only be executed once somebody calls eitherTaskExecutor.syncPoint()orTaskExecutor.syncUntil(BooleanSupplier)on this task executor's main thread.- Specified by:
scheduleForMainThreadin interfaceTaskExecutor- Parameters:
runnable- The task to run.
-
syncPoint
public void syncPoint()Description copied from interface:TaskExecutorWait for all running tasks to finish.
This is useful as a nuclear option, but most of the time you should try to usesyncUntil.- Specified by:
syncPointin interfaceTaskExecutor
-
syncUntil
Description copied from interface:TaskExecutorWait for running tasks, until the given condition is met (BooleanSupplier.getAsBoolean()returnstrue).
This method is equivalent tosyncWhile(() -> !cond.getAsBoolean()).- Specified by:
syncUntilin interfaceTaskExecutor- Parameters:
cond- The condition to wait for.- Returns:
trueif the condition is met.falseif this executor runs out of tasks before the condition is met.
-
syncWhile
Description copied from interface:TaskExecutorWait for running tasks, so long as the given condition is met (BooleanSupplier.getAsBoolean()returnstrue).
If this method is called on the
This method is equivalent tosyncUntil(() -> !cond.getAsBoolean()).- Specified by:
syncWhilein interfaceTaskExecutor- Parameters:
cond- The condition sync on.- Returns:
trueif the condition is no longer met.falseif this executor runs out of tasks while the condition is still met.
-
threadCount
public int threadCount()Description copied from interface:TaskExecutorCheck for the number of threads this executor uses.
May be helpful when determining how many chunks to divide a task into.- Specified by:
threadCountin interfaceTaskExecutor- Returns:
- The number of threads this executor uses.
-
isMainThread
public boolean isMainThread()Description copied from interface:TaskExecutorCheck whether the current thread is this task executor's main thread.- Specified by:
isMainThreadin interfaceTaskExecutor- Returns:
trueif the current thread is the main thread.
-