Class TaskBase

  • All Implemented Interfaces:
    Runnable
    Direct Known Subclasses:
    FunctionTask, RunnableTask

    public abstract class TaskBase
    extends Object
    implements Runnable
    Helper class to provide a Runnable queue implementation with a Runnable wrapper which notifies after execution for the invokeAndWait() semantics.
    • Field Detail

      • syncObject

        protected final Object syncObject
      • catchExceptions

        protected final boolean catchExceptions
      • exceptionOut

        protected final PrintStream exceptionOut
      • sourceStack

        protected final Throwable sourceStack
      • attachment

        protected Object attachment
      • runnableException

        protected Throwable runnableException
      • tCreated

        protected long tCreated
      • tStarted

        protected long tStarted
      • tExecuted

        protected volatile long tExecuted
      • isExecuted

        protected volatile boolean isExecuted
      • isFlushed

        protected volatile boolean isFlushed
      • execThread

        protected volatile Thread execThread
    • Constructor Detail

      • TaskBase

        protected TaskBase​(Object syncObject,
                           boolean catchExceptions,
                           PrintStream exceptionOut)
        Parameters:
        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 getThrowable(), otherwise the exception is thrown.
        exceptionOut - If not null, exceptions are written to this PrintStream.
    • Method Detail

      • getExceptionOutIntro

        protected final String getExceptionOutIntro()
      • printSourceTrace

        protected final void printSourceTrace()
      • getExecutionThread

        public final Thread getExecutionThread()
        Returns the execution thread or null if not yet run().
        Since:
        2.3.2
      • getSyncObject

        public final Object getSyncObject()
        Return the synchronization object if any.
        See Also:
        #RunnableTask(Runnable, Object, boolean)
      • setAttachment

        public final void setAttachment​(Object o)
        Attach a custom object to this task. Useful to piggybag further information, ie tag a task final.
      • run

        public abstract void run()
        Specified by:
        run in interface Runnable
      • flush

        public final void flush​(Throwable t)
        Simply flush this task and notify a waiting executor. The executor which might have been blocked until notified will be unblocked and the task removed from the queue.
        Parameters:
        t - optional Throwable to be assigned for later getThrowable() query in case of an error.
        See Also:
        isFlushed(), isInQueue()
      • isExecuted

        public final boolean isExecuted()
        Returns:
        True if executed, otherwise false;
      • isFlushed

        public final boolean isFlushed()
        Returns:
        True if flushed, otherwise false;
      • hasWaiter

        public final boolean hasWaiter()
        Returns:
        True if invoking thread waits until done, ie a notifyObject was passed, otherwise false;
      • getThrowable

        public final Throwable getThrowable()
        Returns:
        A thrown exception while execution of the user action, if any and if caught
        See Also:
        #RunnableTask(Runnable, Object, boolean)
      • getTimestampCreate

        public final long getTimestampCreate()
      • getTimestampBeforeExec

        public final long getTimestampBeforeExec()
      • getTimestampAfterExec

        public final long getTimestampAfterExec()
      • getDurationInQueue

        public final long getDurationInQueue()
      • getDurationInExec

        public final long getDurationInExec()
      • getDurationTotal

        public final long getDurationTotal()