# Class: com.pnfsoftware.jeb.util.concurrent.ActiveTask

A runnable that can control its own execution. Tasks extending this class must implement the [#runi()](#runi()) method. Client code can [start a task](#start(Runnable)), request cancellation and/or interruption, as well as join for the task to terminate \(either normal termination or a forced termination resulting from a cancel/interrupt request\). 

 This class is similar to some implementation of [futures](Future) \(albeit, its interface is simpler\). The underlying execution primitive \(the thread\) is indirectly accessible via the [#join()](#join()) method; in particular, this class should be used if the client code wants to explicitly join on the underlying thread.

## Constructor: ActiveTask
- parameter: `name`, type: `java.lang.String`

Description: Create an active task.
parameter: name: task name

## Method: cancel
- return type: `boolean`

Description: Request cancellation and return. The thread is interrupted.
return: true if the thread was alive and has been cancelled

## Method: cancel
- parameter: `interruptThread`, type: `boolean`
- return type: `boolean`

Description: Request cancellation and return.
parameter: interruptThread: true to also interrupt the thread
return: true if the thread was alive and has been cancelled

## Method: interrupt
- return type: `boolean`

Description: Request an interruption of the task's thread. **This method is non blocking**.
return: true if the task thread was alive and was interrupted

## Method: isCancelled
- return type: `boolean`

Description: Determine whether cancellation was requested.
return: true if [#cancel()](#cancel()) or [#cancel(boolean)](#cancel(boolean)) was called

## Method: isDone
- return type: `boolean`

Description: Determine whether this task is not running.
return: true if no task thread exists or the task thread has terminated

## Method: join
- return type: `boolean`

Description: Wait indefinitely for the task thread to terminate.
return: true after the wait completed
throws: if the current thread was interrupted while waiting

## Method: join
- parameter: `millis`, type: `long`
- return type: `boolean`

Description: Wait for the task thread to terminate.
parameter: millis: maximum time to wait, in milliseconds; 0 means wait indefinitely
return: true after the wait completed
throws: if the current thread was interrupted while waiting

## Protected Method: onException
- parameter: `e`, type: `java.lang.Exception`

Description: Executed in async mode only \(in sync mode, exceptions happening during execution are not caught\). The default implementation logs the error and does not rethrow it.
parameter: e: exception raised by [#runi()](#runi())

## Protected Method: onPostExecution

Description: Executed in sync or async mode. Default implementation does nothing.

## Protected Method: onPreExecution

Description: Executed in sync or async mode. Default implementation does nothing.

## Method: run

Description: Careful not to call when currently executed \(sync or async\).

## Method: runi

Description: Execute the task body.

## Method: start
- parameter: `completion`, type: `java.lang.Runnable`
- return type: `boolean`

Description: Execute this task on a new daemon thread. If a task has already been started and has not completed, a new task will not be started and instead this method will return false.
parameter: completion: optional runnable that will be executed upon completion, no matter the            outcome \(even if an exception raised\); the execution will take place on the task's            thread
return: true if a new task was started, false otherwise

