com.jogamp.common.util

## Class RunnableTask

- java.lang.Object
- - com.jogamp.common.util.TaskBase
  - - com.jogamp.common.util.RunnableTask

- All Implemented Interfaces:
    Runnable

      public class RunnableTask
      extends TaskBase

  Helper class to provide a Runnable queue implementation with a Runnable wrapper which notifies after execution for the `invokeAndWait()` semantics.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Runnable` | `runnable`

    - ### Fields inherited from class com.jogamp.common.util.TaskBase

      `attachment, catchExceptions, exceptionOut, isFlushed, runnableException, sourceStack, syncObject, tCreated, tExecuted, tStarted`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RunnableTask(Runnable runnable, Object syncObject, boolean catchExceptions, PrintStream exceptionOut)` Create a RunnableTask object w/ synchronization, ie.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Runnable` | `getRunnable()` Return the user action
    `static void` | `invoke(boolean waitUntilDone, Runnable runnable)` Invokes `runnable` on the current thread.
    `static Thread` | `invokeOnNewThread(ThreadGroup tg, boolean waitUntilDone, Runnable runnable, String threadName)` Invokes `runnable` on a new thread belonging to the given `ThreadGroup`.
    `void` | `run()`

    - ### Methods inherited from class com.jogamp.common.util.TaskBase

      `flush, getAttachment, getDurationInExec, getDurationInQueue, getDurationTotal, getExceptionOutIntro, getSyncObject, getThrowable, getTimestampAfterExec, getTimestampBeforeExec, getTimestampCreate, hasWaiter, isExecuted, isFlushed, isInQueue, printSourceTrace, setAttachment, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### runnable

          protected final Runnable runnable

  - ### Constructor Detail

    - #### RunnableTask

          public RunnableTask(Runnable runnable,
                      Object syncObject,
                      boolean catchExceptions,
                      PrintStream exceptionOut)

      Create a RunnableTask object w/ synchronization, ie. suitable for `invokeAndWait()`, i.e. `invoke(true, runnable)`.
      Parameters:
        `runnable` - The user action
        `syncObject` - The synchronization object if caller wait until `runnable` execution is completed, or `null` if waiting is not desired.
        `catchExceptions` - Influence an occurring exception during `runnable` execution. If `true`, the exception is silenced and can be retrieved via `TaskBase.getThrowable()`, otherwise the exception is thrown.
        `exceptionOut` - If not `null`, exceptions are written to this `PrintStream`.

  - ### Method Detail

    - #### invoke

          public static void invoke(boolean waitUntilDone,
                    Runnable runnable)

      Invokes `runnable` on the current thread.
      Parameters:
        `waitUntilDone` - if `true`, waits until `runnable` execution is completed, otherwise returns immediately.
        `runnable` - the `Runnable` to execute.

    - #### invokeOnNewThread

          public static Thread invokeOnNewThread(ThreadGroup tg,
                                 boolean waitUntilDone,
                                 Runnable runnable,
                                 String threadName)

      Invokes `runnable` on a new thread belonging to the given `ThreadGroup`.
      Parameters:
        `tg` - the `ThreadGroup` for the new thread, maybe `null`
        `waitUntilDone` - if `true`, waits until `runnable` execution is completed, otherwise returns immediately.
        `runnable` - the `Runnable` to execute on the new thread. If `waitUntilDone` is `true`, the runnable must exist, i.e. not loop forever.
        `threadName` - the name for the new thread
      Returns:
        the newly created `Thread`

    - #### getRunnable

          public final Runnable getRunnable()

      Return the user action

    - #### run

          public final void run()

      Specified by:
        `run` in interface `Runnable`
      Specified by:
        `run` in class `TaskBase`