GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
com.jogamp.common.util.WorkerThread Class Reference

A re-start()'able, pause(boolean)'able and interrupt'able worker thread with an optional minimum execution duration, see getSleptDuration() executing a task periodically. More...

Collaboration diagram for com.jogamp.common.util.WorkerThread:

Classes

interface  Callback
 An interruptible task periodically executed on the WorkerThread thread. More...
 
interface  StateCallback
 An interruptible State task on the WorkerThread thread. More...
 

Public Member Functions

 WorkerThread (final Duration minPeriod, final Duration minDelay, final boolean daemonThread, final Callback work)
 Instantiates a new WorkerThread. More...
 
 WorkerThread (final Duration minPeriod, final Duration minDelay, final boolean daemonThread, final Callback work, final StateCallback stateChangeCB)
 Instantiates a new WorkerThread. More...
 
final synchronized void start (final boolean paused)
 Starts execution of a new worker thread if not isRunning, i.e. More...
 
final synchronized void stop (final boolean waitUntilDone)
 Stops execution of the start()'ed worker thread. More...
 
final synchronized void pause (final boolean waitUntilDone)
 Pauses execution of the start()'ed worker thread. More...
 
final synchronized void resume ()
 Resumes execution of the pause(boolean)'ed worker thread. More...
 
final boolean isRunning ()
 Returns true if the worker thread has started via start() and has not ended, e.g. More...
 
final boolean isActive ()
 Returns true if the worker thread isRunning() and is not paused. More...
 
final boolean isPaused ()
 Returns true if the worker thread isRunning() and is paused. More...
 
final boolean hasError ()
 Returns true if an exception occured during Callable work execution. More...
 
final Thread getThread ()
 Returns the worker thread if isRunning(), otherwise null. More...
 
final Exception getError (final boolean clear)
 Returns the exception is hasError(). More...
 
final Duration getMinPeriod ()
 Returns enforced minimum work-loop-period or Duration#ZERO for none. More...
 
final Duration getMinDelay ()
 Returns enforced minimum work-loop-delay or Duration#ZERO for none. More...
 
final Duration getSleptDuration ()
 Returns the slept Duration delta of getMinPeriod() and consumed Callback#run() duration, which minimum is getMinDelay(). More...
 
String toString ()
 

Detailed Description

A re-start()'able, pause(boolean)'able and interrupt'able worker thread with an optional minimum execution duration, see getSleptDuration() executing a task periodically.

Optionally a state task can be given for fine grained control.

If an exception occurs during execution of the work Callback, the worker thread is pause(boolean)'ed and hasError() as well as getError(boolean) can be used to query and clear the state. User may resume() or stop() the thread.

If an exception occurs during execution of the optional state task, the worker thread is stop()'ed and hasError() as well as getError(boolean) can be used to query and clear the state.

Definition at line 55 of file WorkerThread.java.

Constructor & Destructor Documentation

◆ WorkerThread() [1/2]

com.jogamp.common.util.WorkerThread.WorkerThread ( final Duration  minPeriod,
final Duration  minDelay,
final boolean  daemonThread,
final Callback  work 
)

Instantiates a new WorkerThread.

Parameters
minPeriodminimum work-loop-period to throttle execution or null if unthrottled, see getSleptDuration()
minDelayminimum work-loop-delay to throttle execution or null if unthrottled, see getSleptDuration()
daemonThreadargument for Thread#setDaemon(boolean)
workthe actual work Callback to perform.

Definition at line 115 of file WorkerThread.java.

◆ WorkerThread() [2/2]

com.jogamp.common.util.WorkerThread.WorkerThread ( final Duration  minPeriod,
final Duration  minDelay,
final boolean  daemonThread,
final Callback  work,
final StateCallback  stateChangeCB 
)

Instantiates a new WorkerThread.

Parameters
minPeriodminimum work-loop-period to throttle execution or null if unthrottled, see getSleptDuration()
minDelayminimum work-loop-delay to throttle execution or null if unthrottled, see getSleptDuration()
daemonThreadargument for Thread#setDaemon(boolean)
workthe actual work Callback to perform.
stateChangeCBoptional StateCallback called at different StateCallback.State changes while locked

Definition at line 127 of file WorkerThread.java.

Member Function Documentation

◆ getError()

final Exception com.jogamp.common.util.WorkerThread.getError ( final boolean  clear)

Returns the exception is hasError().

Parameters
clearif true, clear the exception

Definition at line 266 of file WorkerThread.java.

Here is the caller graph for this function:

◆ getMinDelay()

final Duration com.jogamp.common.util.WorkerThread.getMinDelay ( )

Returns enforced minimum work-loop-delay or Duration#ZERO for none.

See also
getSleptDuration()

Definition at line 278 of file WorkerThread.java.

◆ getMinPeriod()

final Duration com.jogamp.common.util.WorkerThread.getMinPeriod ( )

Returns enforced minimum work-loop-period or Duration#ZERO for none.

See also
getSleptDuration()

Definition at line 272 of file WorkerThread.java.

◆ getSleptDuration()

final Duration com.jogamp.common.util.WorkerThread.getSleptDuration ( )

Returns the slept Duration delta of getMinPeriod() and consumed Callback#run() duration, which minimum is getMinDelay().

Returns zero for zero getMinPeriod() and getMinDelay() or exceeding Callback#run() duration without getMinDelay().

Definition at line 288 of file WorkerThread.java.

Here is the caller graph for this function:

◆ getThread()

final Thread com.jogamp.common.util.WorkerThread.getThread ( )

Returns the worker thread if isRunning(), otherwise null.

Definition at line 260 of file WorkerThread.java.

◆ hasError()

final boolean com.jogamp.common.util.WorkerThread.hasError ( )

Returns true if an exception occured during Callable work execution.

Definition at line 258 of file WorkerThread.java.

Here is the caller graph for this function:

◆ isActive()

final boolean com.jogamp.common.util.WorkerThread.isActive ( )

Returns true if the worker thread isRunning() and is not paused.

Definition at line 254 of file WorkerThread.java.

◆ isPaused()

final boolean com.jogamp.common.util.WorkerThread.isPaused ( )

Returns true if the worker thread isRunning() and is paused.

Definition at line 256 of file WorkerThread.java.

◆ isRunning()

final boolean com.jogamp.common.util.WorkerThread.isRunning ( )

Returns true if the worker thread has started via start() and has not ended, e.g.

via stop(). It might be paused.

Definition at line 252 of file WorkerThread.java.

◆ pause()

final synchronized void com.jogamp.common.util.WorkerThread.pause ( final boolean  waitUntilDone)

Pauses execution of the start()'ed worker thread.

Method blocks until worker thread has been isActive()'ated if waitUntilDone is true.

Definition at line 213 of file WorkerThread.java.

Here is the caller graph for this function:

◆ resume()

final synchronized void com.jogamp.common.util.WorkerThread.resume ( )

Resumes execution of the pause(boolean)'ed worker thread.

Definition at line 234 of file WorkerThread.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start()

final synchronized void com.jogamp.common.util.WorkerThread.start ( final boolean  paused)

Starts execution of a new worker thread if not isRunning, i.e.

never start()'ed or stop()'ed.

Method blocks until the new worker thread has been started and isRunning() and isActive() if paused == false.

Parameters
pausedif true, keeps the new worker thread paused, otherwise resume() it.

Definition at line 149 of file WorkerThread.java.

◆ stop()

final synchronized void com.jogamp.common.util.WorkerThread.stop ( final boolean  waitUntilDone)

Stops execution of the start()'ed worker thread.

Method blocks until worker thread has been stopped if waitUntilDone is true.

Definition at line 186 of file WorkerThread.java.

◆ toString()

String com.jogamp.common.util.WorkerThread.toString ( )

Definition at line 291 of file WorkerThread.java.


The documentation for this class was generated from the following file: