# CountedCompleter

public abstract class **CountedCompleter** extends [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<T\>  
A `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html` with a completion action performed when
triggered and there are no remaining pending actions.
CountedCompleters are in general more robust in the
presence of subtask stalls and blockage than are other forms of
ForkJoinTasks, but are less intuitive to program. Uses of
CountedCompleter are similar to those of other completion based
components (such as `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html`)
except that multiple *pending* completions may be necessary
to trigger the completion action `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)`,
not just one.
Unless initialized otherwise, the {@linkplain #getPendingCount pending
count} starts at zero, but may be (atomically) changed using
methods `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#setPendingCount(int)`, `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#addToPendingCount(int)`, and
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#compareAndSetPendingCount(int,%20int)`. Upon invocation of `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#tryComplete()`, if the pending action count is nonzero, it is
decremented; otherwise, the completion action is performed, and if
this completer itself has a completer, the process is continued
with its completer. As is the case with related synchronization
components such as `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Phaser.html` and
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Semaphore.html`, these methods
affect only internal counts; they do not establish any further
internal bookkeeping. In particular, the identities of pending
tasks are not maintained. As illustrated below, you can create
subclasses that do record some or all pending tasks or their
results when needed. As illustrated below, utility methods
supporting customization of completion traversals are also
provided. However, because CountedCompleters provide only basic
synchronization mechanisms, it may be useful to create further
abstract subclasses that maintain linkages, fields, and additional
support methods appropriate for a set of related usages.

A concrete CountedCompleter class must define method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#compute()`, that should in most cases (as illustrated below), invoke
`tryComplete()` once before returning. The class may also
optionally override method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)`
to perform an action upon normal completion, and method
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onExceptionalCompletion(java.lang.Throwable,%20java.util.concurrent.CountedCompleter<?>)` to
perform an action upon any exception.

CountedCompleters most often do not bear results, in which case
they are normally declared as `CountedCompleter<Void>`, and
will always return `null` as a result value. In other cases,
you should override method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#getRawResult()` to provide a
result from `join(), invoke()`, and related methods. In
general, this method should return the value of a field (or a
function of one or more fields) of the CountedCompleter object that
holds the result upon completion. Method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#setRawResult(T)` by
default plays no role in CountedCompleters. It is possible, but
rarely applicable, to override this method to maintain other
objects or fields holding result data.

A CountedCompleter that does not itself have a completer (i.e.,
one for which `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#getCompleter()` returns `null`) can be
used as a regular ForkJoinTask with this added functionality.
However, any completer that in turn has another completer serves
only as an internal helper for other computations, so its own task
status (as reported in methods such as `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#isDone()`)
is arbitrary; this status changes only upon explicit invocations of
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#complete(T)`, `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#cancel(boolean)`,
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#completeExceptionally(java.lang.Throwable)` or upon
exceptional completion of method `compute`. Upon any
exceptional completion, the exception may be relayed to a task's
completer (and its completer, and so on), if one exists and it has
not otherwise already completed. Similarly, cancelling an internal
CountedCompleter has only a local effect on that completer, so is
not often useful.

**Sample Usages.**

**Parallel recursive decomposition.** CountedCompleters may
be arranged in trees similar to those often used with `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/RecursiveAction.html`s, although the constructions involved in setting
them up typically vary. Here, the completer of each task is its
parent in the computation tree. Even though they entail a bit more
bookkeeping, CountedCompleters may be better choices when applying
a possibly time-consuming operation (that cannot be further
subdivided) to each element of an array or collection; especially
when the operation takes a significantly different amount of time
to complete for some elements than others, either because of
intrinsic variation (for example I/O) or auxiliary effects such as
garbage collection. Because CountedCompleters provide their own
continuations, other threads need not block waiting to perform
them.

For example, here is an initial version of a class that uses
divide-by-two recursive decomposition to divide work into single
pieces (leaf tasks). Even when work is split into individual calls,
tree-based techniques are usually preferable to directly forking
leaf tasks, because they reduce inter-thread communication and
improve load balancing. In the recursive case, the second of each
pair of subtasks to finish triggers completion of its parent
(because no result combination is performed, the default no-op
implementation of method `onCompletion` is not overridden).
A static utility method sets up the base task and invokes it
(here, implicitly using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinPool.html#commonPool()`).

     class MyOperation<E> { void apply(E e) { ... }  }

     class ForEach<E> extends CountedCompleter<Void> {

       public static <E> void forEach(E[] array, MyOperation<E> op) {
         new ForEach<E>(null, array, op, 0, array.length).invoke();
       }

       final E[] array; final MyOperation<E> op; final int lo, hi;
       ForEach(CountedCompleter<?> p, E[] array, MyOperation<E> op, int lo, int hi) {
         super(p);
         this.array = array; this.op = op; this.lo = lo; this.hi = hi;
       }

       public void compute() { // version 1
         if (hi - lo >= 2) {
           int mid = (lo + hi) >>> 1;
           setPendingCount(2); // must set pending count before fork
           new ForEach(this, array, op, mid, hi).fork(); // right child
           new ForEach(this, array, op, lo, mid).fork(); // left child
         }
         else if (hi > lo)
           op.apply(array[lo]);
         tryComplete();
       }
     }

This design can be improved by noticing that in the recursive case, the task has nothing to do after forking its right task, so can directly invoke its left task before returning. (This is an analog of tail recursion removal.) Also, because the task returns upon executing its left task (rather than falling through to invoke `tryComplete`) the pending count is set to one:

     class ForEach<E> ... {
       ...
       public void compute() { // version 2
         if (hi - lo >= 2) {
           int mid = (lo + hi) >>> 1;
           setPendingCount(1); // only one pending
           new ForEach(this, array, op, mid, hi).fork(); // right child
           new ForEach(this, array, op, lo, mid).compute(); // direct invoke
         }
         else {
           if (hi > lo)
             op.apply(array[lo]);
           tryComplete();
         }
       }
     }

As a further optimization, notice that the left task need not even exist. Instead of creating a new one, we can iterate using the original task, and add a pending count for each fork. Additionally, because no task in this tree implements an `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)` method, `tryComplete()` can be replaced with `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#propagateCompletion()`.

     class ForEach<E> ... {
       ...
       public void compute() { // version 3
         int l = lo, h = hi;
         while (h - l >= 2) {
           int mid = (l + h) >>> 1;
           addToPendingCount(1);
           new ForEach(this, array, op, mid, h).fork(); // right child
           h = mid;
         }
         if (h > l)
           op.apply(array[l]);
         propagateCompletion();
       }
     }

Additional optimizations of such classes might entail precomputing pending counts so that they can be established in constructors, specializing classes for leaf steps, subdividing by say, four, instead of two per iteration, and using an adaptive threshold instead of always subdividing down to single elements.

**Searching.** A tree of CountedCompleters can search for a
value or property in different parts of a data structure, and
report a result in an `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/atomic/AtomicReference.html` as
soon as one is found. The others can poll the result to avoid
unnecessary work. (You could additionally {@linkplain #cancel
cancel} other tasks, but it is usually simpler and more efficient
to just let them notice that the result is set and if so skip
further processing.) Illustrating again with an array using full
partitioning (again, in practice, leaf tasks will almost always
process more than one element):

     class Searcher<E> extends CountedCompleter<E> {
       final E[] array; final AtomicReference<E> result; final int lo, hi;
       Searcher(CountedCompleter<?> p, E[] array, AtomicReference<E> result, int lo, int hi) {
         super(p);
         this.array = array; this.result = result; this.lo = lo; this.hi = hi;
       }
       public E getRawResult() { return result.get(); }
       public void compute() { // similar to ForEach version 3
         int l = lo, h = hi;
         while (result.get() == null && h >= l) {
           if (h - l >= 2) {
             int mid = (l + h) >>> 1;
             addToPendingCount(1);
             new Searcher(this, array, result, mid, h).fork();
             h = mid;
           }
           else {
             E x = array[l];
             if (matches(x) && result.compareAndSet(null, x))
               quietlyCompleteRoot(); // root task is now joinable
             break;
           }
         }
         tryComplete(); // normally complete whether or not found
       }
       boolean matches(E e) { ... } // return true if found

       public static <E> E search(E[] array) {
           return new Searcher<E>(null, array, new AtomicReference<E>(), 0, array.length).invoke();
       }
     }

In this example, as well as others in which tasks have no other effects except to `compareAndSet` a common result, the trailing unconditional invocation of `tryComplete` could be made conditional (`if (result.get() == null) tryComplete();`) because no further bookkeeping is required to manage completions once the root task completes.

**Recording subtasks.** CountedCompleter tasks that combine
results of multiple subtasks usually need to access these results
in method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)`. As illustrated in the following
class (that performs a simplified form of map-reduce where mappings
and reductions are all of type `E`), one way to do this in
divide and conquer designs is to have each subtask record its
sibling, so that it can be accessed in method `onCompletion`.
This technique applies to reductions in which the order of
combining left and right results does not matter; ordered
reductions require explicit left/right designations. Variants of
other streamlinings seen in the above examples may also apply.

     class MyMapper<E> { E apply(E v) {  ...  } }
     class MyReducer<E> { E apply(E x, E y) {  ...  } }
     class MapReducer<E> extends CountedCompleter<E> {
       final E[] array; final MyMapper<E> mapper;
       final MyReducer<E> reducer; final int lo, hi;
       MapReducer<E> sibling;
       E result;
       MapReducer(CountedCompleter<?> p, E[] array, MyMapper<E> mapper,
                  MyReducer<E> reducer, int lo, int hi) {
         super(p);
         this.array = array; this.mapper = mapper;
         this.reducer = reducer; this.lo = lo; this.hi = hi;
       }
       public void compute() {
         if (hi - lo >= 2) {
           int mid = (lo + hi) >>> 1;
           MapReducer<E> left = new MapReducer(this, array, mapper, reducer, lo, mid);
           MapReducer<E> right = new MapReducer(this, array, mapper, reducer, mid, hi);
           left.sibling = right;
           right.sibling = left;
           setPendingCount(1); // only right is pending
           right.fork();
           left.compute();     // directly execute left
         }
         else {
           if (hi > lo)
               result = mapper.apply(array[lo]);
           tryComplete();
         }
       }
       public void onCompletion(CountedCompleter<?> caller) {
         if (caller != this) {
           MapReducer<E> child = (MapReducer<E>)caller;
           MapReducer<E> sib = child.sibling;
           if (sib == null || sib.result == null)
             result = child.result;
           else
             result = reducer.apply(child.result, sib.result);
         }
       }
       public E getRawResult() { return result; }

       public static <E> E mapReduce(E[] array, MyMapper<E> mapper, MyReducer<E> reducer) {
         return new MapReducer<E>(null, array, mapper, reducer,
                                  0, array.length).invoke();
       }
     }

Here, method `onCompletion` takes a form common to many completion designs that combine results. This callback-style method is triggered once per task, in either of the two different contexts in which the pending count is, or becomes, zero: (1) by a task itself, if its pending count is zero upon invocation of `tryComplete`, or (2) by any of its subtasks when they complete and decrement the pending count to zero. The `caller` argument distinguishes cases. Most often, when the caller is `this`, no action is necessary. Otherwise the caller argument can be used (usually via a cast) to supply a value (and/or links to other values) to be combined. Assuming proper use of pending counts, the actions inside `onCompletion` occur (once) upon completion of a task and its subtasks. No additional synchronization is required within this method to ensure thread safety of accesses to fields of this task or other completed tasks.

**Completion Traversals** . If using `onCompletion` to
process completions is inapplicable or inconvenient, you can use
methods `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#firstComplete()` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#nextComplete()` to create
custom traversals. For example, to define a MapReducer that only
splits out right-hand tasks in the form of the third ForEach
example, the completions must cooperatively reduce along
unexhausted subtask links, which can be done as follows:

     class MapReducer<E> extends CountedCompleter<E> { // version 2
       final E[] array; final MyMapper<E> mapper;
       final MyReducer<E> reducer; final int lo, hi;
       MapReducer<E> forks, next; // record subtask forks in list
       E result;
       MapReducer(CountedCompleter<?> p, E[] array, MyMapper<E> mapper,
                  MyReducer<E> reducer, int lo, int hi, MapReducer<E> next) {
         super(p);
         this.array = array; this.mapper = mapper;
         this.reducer = reducer; this.lo = lo; this.hi = hi;
         this.next = next;
       }
       public void compute() {
         int l = lo, h = hi;
         while (h - l >= 2) {
           int mid = (l + h) >>> 1;
           addToPendingCount(1);
           (forks = new MapReducer(this, array, mapper, reducer, mid, h, forks)).fork();
           h = mid;
         }
         if (h > l)
           result = mapper.apply(array[l]);
         // process completions by reducing along and advancing subtask links
         for (CountedCompleter<?> c = firstComplete(); c != null; c = c.nextComplete()) {
           for (MapReducer t = (MapReducer)c, s = t.forks; s != null; s = t.forks = s.next)
             t.result = reducer.apply(t.result, s.result);
         }
       }
       public E getRawResult() { return result; }

       public static <E> E mapReduce(E[] array, MyMapper<E> mapper, MyReducer<E> reducer) {
         return new MapReducer<E>(null, array, mapper, reducer,
                                  0, array.length, null).invoke();
       }
     }

**Triggers.** Some CountedCompleters are themselves never
forked, but instead serve as bits of plumbing in other designs;
including those in which the completion of one or more async tasks
triggers another async task. For example:

     class HeaderBuilder extends CountedCompleter<...> { ... }
     class BodyBuilder extends CountedCompleter<...> { ... }
     class PacketSender extends CountedCompleter<...> {
       PacketSender(...) { super(null, 1); ... } // trigger on second completion
       public void compute() { } // never called
       public void onCompletion(CountedCompleter<?> caller) { sendPacket(); }
     }
     // sample use:
     PacketSender p = new PacketSender();
     new HeaderBuilder(p, ...).fork();
     new BodyBuilder(p, ...).fork();

<br />

### Protected Constructor Summary

|---|---|
|   | [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#CountedCompleter(java.util.concurrent.CountedCompleter<?>,%20int))([CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> completer, int initialPendingCount) Creates a new CountedCompleter with the given completer and initial pending count. |
|   | [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#CountedCompleter(java.util.concurrent.CountedCompleter<?>))([CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> completer) Creates a new CountedCompleter with the given completer and an initial pending count of zero. |
|   | [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#CountedCompleter())() Creates a new CountedCompleter with no completer and an initial pending count of zero. |

### Public Method Summary

|---|---|
| final void | [addToPendingCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#addToPendingCount(int))(int delta) Adds (atomically) the given value to the pending count. |
| final boolean | [compareAndSetPendingCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#compareAndSetPendingCount(int,%20int))(int expected, int count) Sets (atomically) the pending count to the given count only if it currently holds the given expected value. |
| void | [complete](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#complete(T))(T rawResult) Regardless of pending count, invokes `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)`, marks this task as complete and further triggers `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#tryComplete()` on this task's completer, if one exists. |
| abstract void | [compute](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#compute())() The main computation performed by this task. |
| final int | [decrementPendingCountUnlessZero](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#decrementPendingCountUnlessZero())() If the pending count is nonzero, (atomically) decrements it. |
| final [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> | [firstComplete](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#firstComplete())() If this task's pending count is zero, returns this task; otherwise decrements its pending count and returns `null`. |
| final [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> | [getCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#getCompleter())() Returns the completer established in this task's constructor, or `null` if none. |
| final int | [getPendingCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#getPendingCount())() Returns the current pending count. |
| T | [getRawResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#getRawResult())() Returns the result of the computation. |
| final [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> | [getRoot](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#getRoot())() Returns the root of the current computation; i.e., this task if it has no completer, else its completer's root. |
| final void | [helpComplete](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#helpComplete(int))(int maxTasks) If this task has not completed, attempts to process at most the given number of other unprocessed tasks for which this task is on the completion path, if any are known to exist. |
| final [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> | [nextComplete](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#nextComplete())() If this task does not have a completer, invokes `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#quietlyComplete()` and returns `null`. |
| void | [onCompletion](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>))([CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> caller) Performs an action when method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#tryComplete()` is invoked and the pending count is zero, or when the unconditional method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#complete(T)` is invoked. |
| boolean | [onExceptionalCompletion](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onExceptionalCompletion(java.lang.Throwable,%20java.util.concurrent.CountedCompleter<?>))([Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) ex, [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> caller) Performs an action when method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#completeExceptionally(java.lang.Throwable)` is invoked or method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#compute()` throws an exception, and this task has not already otherwise completed normally. |
| final void | [propagateCompletion](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#propagateCompletion())() Equivalent to `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#tryComplete()` but does not invoke `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)` along the completion path: If the pending count is nonzero, decrements the count; otherwise, similarly tries to complete this task's completer, if one exists, else marks this task as complete. |
| final void | [quietlyCompleteRoot](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#quietlyCompleteRoot())() Equivalent to `getRoot().quietlyComplete()`. |
| final void | [setPendingCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#setPendingCount(int))(int count) Sets the pending count to the given value. |
| final void | [tryComplete](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#tryComplete())() If the pending count is nonzero, decrements the count; otherwise invokes `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)` and then similarly tries to complete this task's completer, if one exists, else marks this task as complete. |

### Protected Method Summary

|---|---|
| final boolean | [exec](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#exec())() Implements execution conventions for CountedCompleters. |
| void | [setRawResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#setRawResult(T))(T t) A method that result-bearing CountedCompleters may optionally use to help maintain result data. |

### Inherited Method Summary

From class [java.util.concurrent.ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)

|---|---|
| static \<T\> [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<T\> | [adapt](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#adapt(java.lang.Runnable,%20T))([Runnable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Runnable.html) runnable, T result) Returns a new `ForkJoinTask` that performs the `run` method of the given `Runnable` as its action, and returns the given result upon `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#join()`. |
| static [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<?\> | [adapt](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#adapt(java.lang.Runnable))([Runnable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Runnable.html) runnable) Returns a new `ForkJoinTask` that performs the `run` method of the given `Runnable` as its action, and returns a null result upon `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#join()`. |
| static \<T\> [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<T\> | [adapt](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#adapt(java.util.concurrent.Callable<?%20extends%20T>))([Callable](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Callable.html)\<? extends T\> callable) Returns a new `ForkJoinTask` that performs the `call` method of the given `Callable` as its action, and returns its result upon `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#join()`, translating any checked exceptions encountered into `RuntimeException`. |
| boolean | [cancel](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#cancel(boolean))(boolean mayInterruptIfRunning) Attempts to cancel execution of this task. |
| final boolean | [compareAndSetForkJoinTaskTag](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#compareAndSetForkJoinTaskTag(short,%20short))(short expect, short update) Atomically conditionally sets the tag value for this task. |
| void | [complete](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#complete(V))(T value) 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. |
| void | [completeExceptionally](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#completeExceptionally(java.lang.Throwable))([Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) ex) Completes this task abnormally, and if not already aborted or cancelled, causes it to throw the given exception upon `join` and related operations. |
| abstract boolean | [exec](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#exec())() Immediately performs the base action of this task and returns true if, upon return from this method, this task is guaranteed to have completed normally. |
| final [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<T\> | [fork](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#fork())() Arranges to asynchronously execute this task in the pool the current task is running in, if applicable, or using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinPool.html#commonPool()` if not `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#inForkJoinPool()`. |
| final T | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#get(long,%20java.util.concurrent.TimeUnit))(long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit) Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available. |
| final T | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#get())() Waits if necessary for the computation to complete, and then retrieves its result. |
| final [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) | [getException](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#getException())() 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. |
| final short | [getForkJoinTaskTag](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#getForkJoinTaskTag())() Returns the tag for this task. |
| static [ForkJoinPool](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinPool.html) | [getPool](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#getPool())() Returns the pool hosting the current thread, or `null` if the current thread is executing outside of any ForkJoinPool. |
| static int | [getQueuedTaskCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#getQueuedTaskCount())() Returns an estimate of the number of tasks that have been forked by the current worker thread but not yet executed. |
| abstract T | [getRawResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#getRawResult())() Returns the result that would be returned by `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#join()`, even if this task completed abnormally, or `null` if this task is not known to have been completed. |
| static int | [getSurplusQueuedTaskCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#getSurplusQueuedTaskCount())() Returns an estimate of how many more locally queued tasks are held by the current worker thread than there are other worker threads that might steal them, or zero if this thread is not operating in a ForkJoinPool. |
| static void | [helpQuiesce](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#helpQuiesce())() Possibly executes tasks until the pool hosting the current task {@linkplain ForkJoinPool#isQuiescent is quiescent}. |
| static boolean | [inForkJoinPool](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#inForkJoinPool())() Returns `true` if the current thread is a `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinWorkerThread.html` executing as a ForkJoinPool computation. |
| final T | [invoke](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#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. |
| static void | [invokeAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#invokeAll(java.util.concurrent.ForkJoinTask<?>...))([ForkJoinTask...](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<?\> tasks) Forks the given tasks, returning when `isDone` holds for each task or an (unchecked) exception is encountered, in which case the exception is rethrown. |
| static void | [invokeAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#invokeAll(java.util.concurrent.ForkJoinTask<?>,%20java.util.concurrent.ForkJoinTask<?>))([ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<?\> t1, [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<?\> t2) Forks the given tasks, returning when `isDone` holds for each task or an (unchecked) exception is encountered, in which case the exception is rethrown. |
| static \<T extends [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<?\>\> [Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)\<T\> | [invokeAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#invokeAll(java.util.Collection<T>))([Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)\<T\> tasks) Forks all tasks in the specified collection, returning when `isDone` holds for each task or an (unchecked) exception is encountered, in which case the exception is rethrown. |
| final boolean | [isCancelled](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#isCancelled())() Returns `true` if this task was cancelled before it completed normally. |
| final boolean | [isCompletedAbnormally](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#isCompletedAbnormally())() Returns `true` if this task threw an exception or was cancelled. |
| final boolean | [isCompletedNormally](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#isCompletedNormally())() Returns `true` if this task completed without throwing an exception and was not cancelled. |
| final boolean | [isDone](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#isDone())() Returns `true` if this task completed. |
| final T | [join](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#join())() Returns the result of the computation when it `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#isDone()`. |
| static [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<?\> | [peekNextLocalTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#peekNextLocalTask())() Returns, but does not unschedule or execute, a task queued by the current thread but not yet executed, if one is immediately available. |
| static [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<?\> | [pollNextLocalTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#pollNextLocalTask())() Unschedules and returns, without executing, the next task queued by the current thread but not yet executed, if the current thread is operating in a ForkJoinPool. |
| static [ForkJoinTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html)\<?\> | [pollTask](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#pollTask())() If the current thread is operating in a ForkJoinPool, unschedules and returns, without executing, the next task queued by the current thread but not yet executed, if one is available, or if not available, a task that was forked by some other thread, if available. |
| final void | [quietlyComplete](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#quietlyComplete())() Completes this task normally without setting a value. |
| final void | [quietlyInvoke](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#quietlyInvoke())() Commences performing this task and awaits its completion if necessary, without returning its result or throwing its exception. |
| final void | [quietlyJoin](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#quietlyJoin())() Joins this task, without returning its result or throwing its exception. |
| void | [reinitialize](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#reinitialize())() Resets the internal bookkeeping state of this task, allowing a subsequent `fork`. |
| final short | [setForkJoinTaskTag](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#setForkJoinTaskTag(short))(short newValue) Atomically sets the tag value for this task and returns the old value. |
| abstract void | [setRawResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#setRawResult(V))(T value) Forces the given value to be returned as a result. |
| boolean | [tryUnfork](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#tryUnfork())() Tries to unschedule this task for execution. |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.util.concurrent.Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)

|---|---|
| abstract boolean | [cancel](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html#cancel(boolean))(boolean mayInterruptIfRunning) Attempts to cancel execution of this task. |
| abstract T | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html#get(long,%20java.util.concurrent.TimeUnit))(long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit) Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available. |
| abstract T | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html#get())() Waits if necessary for the computation to complete, and then retrieves its result. |
| abstract boolean | [isCancelled](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html#isCancelled())() Returns `true` if this task was cancelled before it completed normally. |
| abstract boolean | [isDone](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html#isDone())() Returns `true` if this task completed. |

## Protected Constructors

#### protected
**CountedCompleter**
([CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> completer, int initialPendingCount)

Creates a new CountedCompleter with the given completer
and initial pending count.

##### Parameters

| completer | this task's completer, or `null` if none |
| initialPendingCount | the initial pending count |
|---|---|

#### protected
**CountedCompleter**
([CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> completer)

Creates a new CountedCompleter with the given completer
and an initial pending count of zero.

##### Parameters

| completer | this task's completer, or `null` if none |
|---|---|

#### protected
**CountedCompleter**
()

Creates a new CountedCompleter with no completer
and an initial pending count of zero.

## Public Methods

#### public final void
**addToPendingCount**
(int delta)

Adds (atomically) the given value to the pending count.

##### Parameters

| delta | the value to add |
|---|---|

#### public final boolean
**compareAndSetPendingCount**
(int expected, int count)

Sets (atomically) the pending count to the given count only if
it currently holds the given expected value.

##### Parameters

| expected | the expected value |
| count | the new value |
|---|---|

##### Returns

- `true` if successful

#### public void
**complete**
(T rawResult)

Regardless of pending count, invokes
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)`, marks this task as
complete and further triggers `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#tryComplete()` on this
task's completer, if one exists. The given rawResult is
used as an argument to `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#setRawResult(T)` before invoking
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)` or marking this task
as complete; its value is meaningful only for classes
overriding `setRawResult`. This method does not modify
the pending count.

This method may be useful when forcing completion as soon as
any one (versus all) of several subtask results are obtained.
However, in the common (and recommended) case in which `setRawResult` is not overridden, this effect can be obtained
more simply using `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#quietlyCompleteRoot()`.

##### Parameters

| rawResult | the raw result |
|---|---|

#### public abstract void
**compute**
()

The main computation performed by this task.

#### public final int
**decrementPendingCountUnlessZero**
()

If the pending count is nonzero, (atomically) decrements it.

##### Returns

- the initial (undecremented) pending count holding on entry to this method

#### public final [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\>
**firstComplete**
()

If this task's pending count is zero, returns this task;
otherwise decrements its pending count and returns `null`.
This method is designed to be used with `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#nextComplete()` in
completion traversal loops.

##### Returns

- this task, if pending count was zero, else `null`

#### public final [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\>
**getCompleter**
()

Returns the completer established in this task's constructor,
or `null` if none.

##### Returns

- the completer

#### public final int
**getPendingCount**
()

Returns the current pending count.

##### Returns

- the current pending count

#### public T
**getRawResult**
()

Returns the result of the computation. By default,
returns `null`, which is appropriate for `Void`
actions, but in other cases should be overridden, almost
always to return a field or function of a field that
holds the result upon completion.

##### Returns

- the result of the computation

#### public final [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\>
**getRoot**
()

Returns the root of the current computation; i.e., this
task if it has no completer, else its completer's root.

##### Returns

- the root of the current computation

#### public final void
**helpComplete**
(int maxTasks)

If this task has not completed, attempts to process at most the
given number of other unprocessed tasks for which this task is
on the completion path, if any are known to exist.

##### Parameters

| maxTasks | the maximum number of tasks to process. If less than or equal to zero, then no tasks are processed. |
|---|---|

#### public final [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\>
**nextComplete**
()

If this task does not have a completer, invokes `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#quietlyComplete()` and returns `null`. Or, if
the completer's pending count is non-zero, decrements that
pending count and returns `null`. Otherwise, returns the
completer. This method can be used as part of a completion
traversal loop for homogeneous task hierarchies:

     for (CountedCompleter<?> c = firstComplete();
          c != null;
          c = c.nextComplete()) {
       // ... process c ...
     }

<br />

##### Returns

- the completer, or `null` if none

#### public void
**onCompletion**
([CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> caller)

Performs an action when method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#tryComplete()` is invoked
and the pending count is zero, or when the unconditional
method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#complete(T)` is invoked. By default, this method
does nothing. You can distinguish cases by checking the
identity of the given caller argument. If not equal to `this`, then it is typically a subtask that may contain results
(and/or links to other results) to combine.

##### Parameters

| caller | the task invoking this method (which may be this task itself) |
|---|---|

#### public boolean
**onExceptionalCompletion**
([Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) ex, [CountedCompleter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html)\<?\> caller)

Performs an action when method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#completeExceptionally(java.lang.Throwable)` is invoked or method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#compute()` throws an exception, and this task has not already
otherwise completed normally. On entry to this method, this task
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/ForkJoinTask.html#isCompletedAbnormally()`. The return value
of this method controls further propagation: If `true`
and this task has a completer that has not completed, then that
completer is also completed exceptionally, with the same
exception as this completer. The default implementation of
this method does nothing except return `true`.

##### Parameters

| ex | the exception |
| caller | the task invoking this method (which may be this task itself) |
|---|---|

##### Returns

- `true` if this exception should be propagated to this task's completer, if one exists

#### public final void
**propagateCompletion**
()

Equivalent to `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#tryComplete()` but does not invoke `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)` along the completion path:
If the pending count is nonzero, decrements the count;
otherwise, similarly tries to complete this task's completer, if
one exists, else marks this task as complete. This method may be
useful in cases where `onCompletion` should not, or need
not, be invoked for each completer in a computation.

#### public final void
**quietlyCompleteRoot**
()

Equivalent to `getRoot().quietlyComplete()`.

#### public final void
**setPendingCount**
(int count)

Sets the pending count to the given value.

##### Parameters

| count | the count |
|---|---|

#### public final void
**tryComplete**
()

If the pending count is nonzero, decrements the count;
otherwise invokes `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/CountedCompleter.html#onCompletion(java.util.concurrent.CountedCompleter<?>)`
and then similarly tries to complete this task's completer,
if one exists, else marks this task as complete.

## Protected Methods

#### protected final boolean
**exec**
()

Implements execution conventions for CountedCompleters.

##### Returns

- `true` if this task is known to have completed normally

#### protected void
**setRawResult**
(T t)

A method that result-bearing CountedCompleters may optionally
use to help maintain result data. By default, does nothing.
Overrides are not recommended. However, if this method is
overridden to update existing objects or fields, then it must
in general be defined to be thread-safe.

##### Parameters

| t | the value |
|---|---|