Package gaiasky.util.concurrent
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 java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AtomicBoolean
protected final AtomicBoolean
protected Runnable
protected final Object
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isAwake()
Queries the thread state.boolean
Whether the thread is running or it is stopped.void
This method offers the new task to the service thread.void
run()
void
stopDaemon
(boolean notifyAll) Stops the daemon iterations when the current task has finished.void
This method does an active wait until the current task is finished.void
wakeUp()
This method wakes up the thread and runs the current task.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, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, 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
public void run()
-