Class ServiceThread
java.lang.Object
java.lang.Thread
gaiasky.util.concurrent.ServiceThread
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
OctreeLoader.OctreeLoaderThread, OrbitRefresher.OrbitUpdaterThread
-
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AtomicBooleanprotected final AtomicBooleanprotected Runnableprotected final ObjectFields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisAwake()Queries the thread state.booleanWhether the thread is running or it is stopped.voidThis method offers the new task to the service thread.voidrun()voidstopDaemon(boolean notifyAll) Stops the daemon iterations when the current task has finished.voidThis method does an active wait until the current task is finished.voidwakeUp()This method wakes up the thread and runs the current task.Methods inherited from class Thread
activeCount, checkAccess, clone, 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, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, threadId, toString, yield
-
Field Details
-
threadLock
-
awake
-
running
-
task
-
-
Constructor Details
-
ServiceThread
public ServiceThread() -
ServiceThread
-
-
Method Details
-
getThreadLock
-
isRunning
public boolean isRunning()Whether the thread is running or it is stopped.- Returns:
- The running state.
-
stopDaemon
public void stopDaemon(boolean notifyAll) Stops the daemon iterations when the current task has finished. -
isAwake
public boolean isAwake()Queries the thread state.- Returns:
- True if the thread is currently running stuff, false otherwise.
-
offerTask
This method offers the new task to the service thread. If the thread is sleeping, the new task is set and executed right away. Otherwise, the method blocks and does a busy wait until the current task finishes.- Parameters:
task- The new task to run.
-
wakeUp
public void wakeUp()This method wakes up the thread and runs the current task. If the thread is sleeping, the task is executed right away. Otherwise, the method blocks and does a busy wait until the current task finishes. -
waitCurrentTask
public void waitCurrentTask()This method does an active wait until the current task is finished. If no task is executed, this returns immediately. -
run
-