Udostępnij za pośrednictwem


ForkJoinPool.IManagedBlocker Interface

Definition

Interface for extending managed parallelism for tasks running in ForkJoinPools.

[Android.Runtime.Register("java/util/concurrent/ForkJoinPool$ManagedBlocker", "", "Java.Util.Concurrent.ForkJoinPool/IManagedBlockerInvoker")]
public interface ForkJoinPool.IManagedBlocker : Android.Runtime.IJavaObject, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("java/util/concurrent/ForkJoinPool$ManagedBlocker", "", "Java.Util.Concurrent.ForkJoinPool/IManagedBlockerInvoker")>]
type ForkJoinPool.IManagedBlocker = interface
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Attributes
Implements

Remarks

Interface for extending managed parallelism for tasks running in ForkJoinPools.

A ManagedBlocker provides two methods. Method #isReleasable must return true if blocking is not necessary. Method #block blocks the current thread if necessary (perhaps internally invoking isReleasable before actually blocking). These actions are performed by any thread invoking ForkJoinPool#managedBlock(ManagedBlocker). The unusual methods in this API accommodate synchronizers that may, but don't usually, block for long periods. Similarly, they allow more efficient internal handling of cases in which additional workers may be, but usually are not, needed to ensure sufficient parallelism. Toward this end, implementations of method isReleasable must be amenable to repeated invocation. Neither method is invoked after a prior invocation of isReleasable or block returns true.

For example, here is a ManagedBlocker based on a ReentrantLock:

{@code
            class ManagedLocker implements ManagedBlocker {
              final ReentrantLock lock;
              boolean hasLock = false;
              ManagedLocker(ReentrantLock lock) { this.lock = lock; }
              public boolean block() {
                if (!hasLock)
                  lock.lock();
                return true;
              }
              public boolean isReleasable() {
                return hasLock || (hasLock = lock.tryLock());
              }
            }}

Here is a class that possibly blocks waiting for an item on a given queue:

{@code
            class QueueTaker<E> implements ManagedBlocker {
              final BlockingQueue<E> queue;
              volatile E item = null;
              QueueTaker(BlockingQueue<E> q) { this.queue = q; }
              public boolean block() throws InterruptedException {
                if (item == null)
                  item = queue.take();
                return true;
              }
              public boolean isReleasable() {
                return item != null || (item = queue.poll()) != null;
              }
              public E getItem() { // call after pool.managedBlock completes
                return item;
              }
            }}

Java documentation for java.util.concurrent.ForkJoinPool.ManagedBlocker.

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.

Properties

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
IsReleasable
JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

Block()

Possibly blocks the current thread, for example waiting for a lock or condition.

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to