jsr166z.forkjoin
Class AsyncAction

java.lang.Object
  extended by jsr166z.forkjoin.ForkJoinTask<java.lang.Void>
      extended by jsr166z.forkjoin.AsyncAction

public abstract class AsyncAction
extends ForkJoinTask<java.lang.Void>

Resultless ForkJoinTasks with explicit completions. Unlike some other kinds of tasks, AsyncActions do not intrinisically complete upon exit from their compute methods, but instead require explicit invocation of their finish methods.

Unlike LinkedAsyncActions, AsyncActions do not establish links to parent tasks or count child tasks. This class can thus form a more flexible basis for classes creating custom linkages.


Constructor Summary
AsyncAction()
           
 
Method Summary
protected abstract  void compute()
          The asynchronous part of the computation performed by this task.
 java.lang.Throwable exec()
          Immediately commences execution of this task by the current worker thread unless already cancelled, returning any exception thrown by its compute method.
 void finish()
          Equivalent to finish(null).
 void finish(java.lang.Void result)
          Completes this task, and if not already aborted or cancelled, returning the given result upon join and related operations.
 void finishExceptionally(java.lang.Throwable ex)
          Completes this task abnormally, and if not already aborted or cancelled, causes it to throw the given exception upon join and related operations.
 java.lang.Void invoke()
          Equivalent in effect to the sequence fork(); join(); but may be more efficient.
 java.lang.Void rawResult()
          Always returns null.
 
Methods inherited from class jsr166z.forkjoin.ForkJoinTask
cancel, fork, getException, isCancelled, isDone, isStolen, join, quietlyJoin, reinitialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncAction

public AsyncAction()
Method Detail

compute

protected abstract void compute()
The asynchronous part of the computation performed by this task. While you must define this method, you should not in general call it directly (although you can invoke immediately via exec.) If this method throws a Throwable, finishExceptionally is immediately invoked.


finish

public final void finish()
Equivalent to finish(null).


finish

public final void finish(java.lang.Void result)
Description copied from class: ForkJoinTask
Completes this task, and if not already aborted or cancelled, returning the given result upon join and related operations.

Specified by:
finish in class ForkJoinTask<java.lang.Void>
Parameters:
result - the result to return

finishExceptionally

public final void finishExceptionally(java.lang.Throwable ex)
Description copied from class: ForkJoinTask
Completes this task abnormally, and if not already aborted or cancelled, causes it to throw the given exception upon join and related operations.

Specified by:
finishExceptionally in class ForkJoinTask<java.lang.Void>
Parameters:
ex - the exception to throw. While not necessarily statically enforced, this must be a RuntimeException or Error.

rawResult

public final java.lang.Void rawResult()
Always returns null.

Specified by:
rawResult in class ForkJoinTask<java.lang.Void>
Returns:
null

invoke

public final java.lang.Void invoke()
Description copied from class: ForkJoinTask
Equivalent in effect to the sequence fork(); join(); but may be more efficient.

Specified by:
invoke in class ForkJoinTask<java.lang.Void>
Returns:
the computed result

exec

public final java.lang.Throwable exec()
Description copied from class: ForkJoinTask
Immediately commences execution of this task by the current worker thread unless already cancelled, returning any exception thrown by its compute method.

Specified by:
exec in class ForkJoinTask<java.lang.Void>
Returns:
exception thrown by compute (or via cancellation), or null if none