Class PhonWorker
java.lang.Object
java.lang.Thread
ca.phon.worker.PhonWorker
- All Implemented Interfaces:
PropertyChangeListener,Runnable,EventListener
- 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.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) static PhonWorkerCreates a new PhonWorker thread and returns it.static PhonWorkerCreate a new worker using a shared queue.static PhonWorkerGet the static instancestatic PhonWorkergetTasks()booleanhasTasks()voidinvokeLater(Runnable task) Add a task to the queue.static PhonTaskinvokeOnNewWorker(Runnable toRun) static PhonTaskinvokeOnNewWorker(Runnable toRun, Runnable onFinish) static PhonTaskinvokeOnNewWorker(Runnable toRun, Runnable onFinish, PhonTaskErrorHandler onError) Invoke provided runnable on a new thread and return the generated PhonTaskbooleanbooleanstatic booleanTells if the currently running thread is the worker thread.voidvoidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener) voidrun()voidsetFinalTask(Runnable finalTask) voidsetFinishWhenQueueEmpty(boolean finishWhenQueueEmpty) voidsetHaltOnError(boolean haltOnError) voidshutdown()Shutdown the worker thread.Methods inherited from class java.lang.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, stop, 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
-
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) -
addPropertyChangeListener
-
removePropertyChangeListener
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-