Package ca.phon.worker
Class PhonWorker
java.lang.Object
java.lang.Thread
ca.phon.worker.PhonWorker
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
PhonShutdownThread
A worker thread for the application.
Tasks are place on the worker thread using
the invokeLater(Runnable) method.
Tasks are run FIFO.
-
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic PhonWorker
Creates a new PhonWorker thread and returns it.static PhonWorker
Create a new worker using a shared queue.static PhonWorker
Get the static instancestatic PhonWorker
getTasks()
boolean
hasTasks()
void
invokeLater
(Runnable task) Add a task to the queue.static PhonTask
invokeOnNewWorker
(Runnable toRun) static PhonTask
invokeOnNewWorker
(Runnable toRun, Runnable onFinish) static PhonTask
invokeOnNewWorker
(Runnable toRun, Runnable onFinish, PhonTaskErrorHandler onError) Invoke provided runnable on a new thread and return the generated PhonTaskboolean
boolean
static boolean
Tells if the currently running thread is the worker thread.void
run()
void
setFinalTask
(Runnable finalTask) void
setFinishWhenQueueEmpty
(boolean finishWhenQueueEmpty) void
setHaltOnError
(boolean haltOnError) void
shutdown()
Shutdown the worker thread.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, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Constructor Details
-
PhonWorker
protected PhonWorker()Constructor
-
-
Method Details
-
getInstance
Get the static instance -
createWorker
Creates a new PhonWorker thread and returns it. The new thread is not maintained by this class and the reference to it should be kept and shutdown by the requsting class.- Returns:
- a new PhonWorker thread
-
createWorker
Create a new worker using a shared queue.- Returns:
- a new PhonWorker thread
-
invokeOnNewWorker
-
invokeOnNewWorker
-
invokeOnNewWorker
public static PhonTask invokeOnNewWorker(Runnable toRun, Runnable onFinish, PhonTaskErrorHandler onError) Invoke provided runnable on a new thread and return the generated PhonTask- Parameters:
toRun
-onFinish
-
-
invokeLater
Add a task to the queue.- Parameters:
task
-
-
run
public void run() -
getShutdownThread
-
shutdown
public void shutdown()Shutdown the worker thread. The currently executing task must complete first. -
isStaticWorkerThread
public static boolean isStaticWorkerThread()Tells if the currently running thread is the worker thread.- Returns:
- true if we are running in the worker thread, false otherwise
-
hasTasks
public boolean hasTasks() -
isHaltOnError
public boolean isHaltOnError() -
setHaltOnError
public void setHaltOnError(boolean haltOnError) -
getFinalTask
-
setFinalTask
-
getTasks
-
isFinishWhenQueueEmpty
public boolean isFinishWhenQueueEmpty() -
setFinishWhenQueueEmpty
public void setFinishWhenQueueEmpty(boolean finishWhenQueueEmpty)
-