RecursiveTask Class

Definition

A recursive result-bearing ForkJoinTask.

[Android.Runtime.Register("java/util/concurrent/RecursiveTask", DoNotGenerateAcw=true)]
[Java.Interop.JavaTypeParameters(new System.String[] { "V" })]
public abstract class RecursiveTask : Java.Util.Concurrent.ForkJoinTask
[<Android.Runtime.Register("java/util/concurrent/RecursiveTask", DoNotGenerateAcw=true)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "V" })>]
type RecursiveTask = class
    inherit ForkJoinTask
Inheritance
RecursiveTask
Attributes

Remarks

A recursive result-bearing ForkJoinTask.

For example, here is a task-based program for computing Factorials:

{@code
            import java.util.concurrent.RecursiveTask;
            import java.math.BigInteger;
            public class Factorial {
              static class FactorialTask extends RecursiveTask<BigInteger> {
                private final int from, to;
                FactorialTask(int from, int to) { this.from = from; this.to = to; }
                protected BigInteger compute() {
                  int range = to - from;
                  if (range == 0) {                       // base case
                    return BigInteger.valueOf(from);
                  } else if (range == 1) {                // too small to parallelize
                    return BigInteger.valueOf(from).multiply(BigInteger.valueOf(to));
                  } else {                                // split in half
                    int mid = from + range / 2;
                    FactorialTask leftTask = new FactorialTask(from, mid);
                    leftTask.fork();         // perform about half the work locally
                    return new FactorialTask(mid + 1, to).compute()
                           .multiply(leftTask.join());
                  }
                }
              }
              static BigInteger factorial(int n) { // uses ForkJoinPool.commonPool()
                return (n <= 1) ? BigInteger.ONE : new FactorialTask(1, n).invoke();
              }
              public static void main(String[] args) {
                System.out.println(factorial(Integer.parseInt(args[0])));
              }
            }}

Added in 1.7.

Java documentation for java.util.concurrent.RecursiveTask.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Name Description
RecursiveTask()

Constructor for subclasses to call.

RecursiveTask(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

Name Description
Class

Returns the runtime class of this Object.

(Inherited from Object)
Exception

Returns the exception thrown by the base computation, or a CancellationException if cancelled, or null if none or if the method has not yet completed.

(Inherited from ForkJoinTask)
ForkJoinTaskTag

Returns the tag for this task.

(Inherited from ForkJoinTask)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsCancelled

Returns true if this task was cancelled before it completed normally.

(Inherited from ForkJoinTask)
IsCompletedAbnormally

Returns true if this task threw an exception or was cancelled.

(Inherited from ForkJoinTask)
IsCompletedNormally

Returns true if this task completed without throwing an exception and was not cancelled.

(Inherited from ForkJoinTask)
IsDone

Returns true if this task completed.

(Inherited from ForkJoinTask)
JniIdentityHashCode

Gets the identity hash code assigned to this Java peer by the interop runtime.

(Inherited from Object)
JniPeerMembers
PeerReference

Gets the JNI object reference for this Java peer.

(Inherited from Object)
RawRawResult

Returns the result that would be returned by Join(), even if this task completed abnormally, or null if this task is not known to have been completed.

(Inherited from ForkJoinTask)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Name Description
Cancel(Boolean)

Attempts to cancel execution of this task.

(Inherited from ForkJoinTask)
Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CompareAndSetForkJoinTaskTag(Int16, Int16)

Atomically conditionally sets the tag value for this task.

(Inherited from ForkJoinTask)
Complete(Object)

Completes this task, and if not already aborted or cancelled, returning the given value as the result of subsequent invocations of join and related operations.

(Inherited from ForkJoinTask)
CompleteExceptionally(Throwable)

Completes this task abnormally, and if not already aborted or cancelled, causes it to throw the given exception upon join and related operations.

(Inherited from ForkJoinTask)
Compute()

The main computation performed by this task.

Dispose()

Releases the resources held by this Java peer.

(Inherited from Object)
Dispose(Boolean)

Releases the resources held by this Java peer.

(Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
ExceptionNow() (Inherited from ForkJoinTask)
Exec()

Implements execution conventions for RecursiveTask.

Fork()

Arranges to asynchronously execute this task in the pool the current task is running in, if applicable, or using the ForkJoinPool#commonPool() if not #inForkJoinPool.

(Inherited from ForkJoinTask)
Get()

Waits if necessary for the computation to complete, and then retrieves its result.

(Inherited from ForkJoinTask)
Get(Int64, TimeUnit)

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

(Inherited from ForkJoinTask)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
Invoke()

Commences performing this task, awaits its completion if necessary, and returns its result, or throws an (unchecked) RuntimeException or Error if the underlying computation did so.

(Inherited from ForkJoinTask)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Join()

Returns the result of the computation when it #isDone is done.

(Inherited from ForkJoinTask)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
QuietlyComplete()

Completes this task normally without setting a value.

(Inherited from ForkJoinTask)
QuietlyInvoke()

Commences performing this task and awaits its completion if necessary, without returning its result or throwing its exception.

(Inherited from ForkJoinTask)
QuietlyJoin()

Joins this task, without returning its result or throwing its exception.

(Inherited from ForkJoinTask)
QuietlyJoin(Int64, TimeUnit)

Tries to join this task, returning true if it completed (possibly exceptionally) before the given timeout and the current thread has not been interrupted.

(Inherited from ForkJoinTask)
QuietlyJoinUninterruptibly(Int64, TimeUnit)

Tries to join this task, returning true if it completed (possibly exceptionally) before the given timeout.

(Inherited from ForkJoinTask)
Reinitialize()

Resets the internal bookkeeping state of this task, allowing a subsequent fork.

(Inherited from ForkJoinTask)
ResultNow() (Inherited from ForkJoinTask)
SetForkJoinTaskTag(Int16)

Atomically sets the tag value for this task and returns the old value.

(Inherited from ForkJoinTask)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetRawResult(Object)

Forces the given value to be returned as a result.

(Inherited from ForkJoinTask)
State() (Inherited from ForkJoinTask)
ToArray<T>()

Creates a managed array from this Java array wrapper.

(Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
TryUnfork()

Tries to unschedule this task for execution.

(Inherited from ForkJoinTask)
UnregisterFromRuntime()

Unregisters this Java peer from the interop runtime.

(Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

Name Description
IJavaPeerable.Disposed()

Notifies the interop runtime that this managed peer has been disposed.

(Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced()

Releases this Java peer unless it is retained by another managed reference.

(Inherited from Object)
IJavaPeerable.Finalized()

Notifies the interop runtime that this managed peer has been finalized.

(Inherited from Object)
IJavaPeerable.JniManagedPeerState

Gets the state that describes the relationship between this managed peer and its JNI reference.

(Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32)

Sets the interop identity hash code for this Java peer.

(Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

Sets the managed and JNI peer state for this Java peer.

(Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference)

Sets the JNI object reference used by this managed peer.

(Inherited from Object)

Extension Methods

Name Description
GetAsync(IFuture, Int64, TimeUnit)
GetAsync(IFuture)
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to