In order to be used with a selector, an instance of this class must first be registered via the {@link #register(Selector,int,Object) register} method. This method returns a new {@link SelectionKey} objectthat represents the channel's registration with the selector.
Once registered with a selector, a channel remains registered until it is deregistered. This involves deallocating whatever resources were allocated to the channel by the selector.
A channel cannot be deregistered directly; instead, the key representing its registration must be cancelled. Cancelling a key requests that the channel be deregistered during the selector's next selection operation. A key may be cancelled explicitly by invoking its {@link SelectionKey#cancel() cancel} method. All of a channel's keys are cancelledimplicitly when the channel is closed, whether by invoking its {@link Channel#close close} method or by interrupting a thread blocked in an I/Ooperation upon the channel.
If the selector itself is closed then the channel will be deregistered, and the key representing its registration will be invalidated, without further delay.
A channel may be registered at most once with any particular selector.
Whether or not a channel is registered with one or more selectors may be determined by invoking the {@link #isRegistered isRegistered} method.
Selectable channels are safe for use by multiple concurrent threads.
Newly-created selectable channels are always in blocking mode. Non-blocking mode is most useful in conjunction with selector-based multiplexing. A channel must be placed into non-blocking mode before being registered with a selector, and may not be returned to blocking mode until it has been deregistered. @author Mark Reinhold @author JSR-51 Expert Group @version 1.35, 05/11/17 @since 1.4 @see SelectionKey @see Selector
|
|