Dela via


AsynchronousChannelGroup Class

Definition

A grouping of asynchronous channels for the purpose of resource sharing.

[Android.Runtime.Register("java/nio/channels/AsynchronousChannelGroup", ApiSince=26, DoNotGenerateAcw=true)]
public abstract class AsynchronousChannelGroup : Java.Lang.Object
[<Android.Runtime.Register("java/nio/channels/AsynchronousChannelGroup", ApiSince=26, DoNotGenerateAcw=true)>]
type AsynchronousChannelGroup = class
    inherit Object
Inheritance
AsynchronousChannelGroup
Attributes

Remarks

A grouping of asynchronous channels for the purpose of resource sharing.

An asynchronous channel group encapsulates the mechanics required to handle the completion of I/O operations initiated by AsynchronousChannel asynchronous channels that are bound to the group. A group has an associated thread pool to which tasks are submitted to handle I/O events and dispatch to CompletionHandler completion-handlers that consume the result of asynchronous operations performed on channels in the group. In addition to handling I/O events, the pooled threads may also execute other tasks required to support the execution of asynchronous I/O operations.

An asynchronous channel group is created by invoking the #withFixedThreadPool withFixedThreadPool or #withCachedThreadPool withCachedThreadPool methods defined here. Channels are bound to a group by specifying the group when constructing the channel. The associated thread pool is <em>owned</em> by the group; termination of the group results in the shutdown of the associated thread pool.

In addition to groups created explicitly, the Java virtual machine maintains a system-wide <em>default group</em> that is constructed automatically. Asynchronous channels that do not specify a group at construction time are bound to the default group. The default group has an associated thread pool that creates new threads as needed. The default group may be configured by means of system properties defined in the table below. Where the java.util.concurrent.ThreadFactory ThreadFactory for the default group is not configured then the pooled threads of the default group are Thread#isDaemon daemon threads.

<table class="striped"> <caption style="display:none:">System properties</caption> <thead> <tr> <th scope="col">System property</th> <th scope="col">Description</th> </tr> </thead> <tbody> <tr> <th scope="row"> java.nio.channels.DefaultThreadPool.threadFactory</th> <td> The value of this property is taken to be the fully-qualified name of a concrete java.util.concurrent.ThreadFactory ThreadFactory class. The class is loaded using the system class loader and instantiated. The factory's java.util.concurrent.ThreadFactory#newThread newThread method is invoked to create each thread for the default group's thread pool. If the process to load and instantiate the value of the property fails then an unspecified error is thrown during the construction of the default group. </td> </tr> <tr> <th scope="row"> java.nio.channels.DefaultThreadPool.initialSize</th> <td> The value of the initialSize parameter for the default group (see #withCachedThreadPool withCachedThreadPool). The value of the property is taken to be the String representation of an Integer that is the initial size parameter. If the value cannot be parsed as an Integer it causes an unspecified error to be thrown during the construction of the default group. </td> </tr> </tbody> </table>

"threading"><h2>Threading</h2>

The completion handler for an I/O operation initiated on a channel bound to a group is guaranteed to be invoked by one of the pooled threads in the group. This ensures that the completion handler is run by a thread with the expected <em>identity</em>.

Where an I/O operation completes immediately, and the initiating thread is one of the pooled threads in the group then the completion handler may be invoked directly by the initiating thread. To avoid stack overflow, an implementation may impose a limit as to the number of activations on the thread stack. Some I/O operations may prohibit invoking the completion handler directly by the initiating thread (see AsynchronousServerSocketChannel#accept(Object,CompletionHandler) accept).

"shutdown"><h2>Shutdown and Termination</h2>

The #shutdown() shutdown method is used to initiate an <em>orderly shutdown</em> of a group. An orderly shutdown marks the group as shutdown; further attempts to construct a channel that binds to the group will throw ShutdownChannelGroupException. Whether or not a group is shutdown can be tested using the #isShutdown() isShutdown method. Once shutdown, the group <em>terminates</em> when all asynchronous channels that are bound to the group are closed, all actively executing completion handlers have run to completion, and resources used by the group are released. No attempt is made to stop or interrupt threads that are executing completion handlers. The #isTerminated() isTerminated method is used to test if the group has terminated, and the #awaitTermination awaitTermination method can be used to block until the group has terminated.

The #shutdownNow() shutdownNow method can be used to initiate a <em>forceful shutdown</em> of the group. In addition to the actions performed by an orderly shutdown, the shutdownNow method closes all open channels in the group as if by invoking the AsynchronousChannel#close close method.

Added in 1.7.

Java documentation for java.nio.channels.AsynchronousChannelGroup.

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

AsynchronousChannelGroup(AsynchronousChannelProvider)

Initialize a new instance of this class.

AsynchronousChannelGroup(IntPtr, JniHandleOwnership)

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsShutdown
IsTerminated
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass
ThresholdType

Methods

AwaitTermination(Int64, TimeUnit)

Awaits termination of the group.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

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

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
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)
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)
Provider()

Returns the provider that created this channel group.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
Shutdown()

Initiates an orderly shutdown of the group.

ShutdownNow()

Shuts down the group and closes all open channels in the group.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (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)
WithCachedThreadPool(IExecutorService, Int32)

Creates an asynchronous channel group with a given thread pool that creates new threads as needed.

WithFixedThreadPool(Int32, IThreadFactory)

Creates an asynchronous channel group with a fixed thread pool.

WithThreadPool(IExecutorService)

Creates an asynchronous channel group with a given thread pool.

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to