Module java.base

Class AbstractSelector

java.lang.Object
java.nio.channels.Selector
java.nio.channels.spi.AbstractSelector
All Implemented Interfaces:
Closeable, AutoCloseable

public abstract class AbstractSelector extends Selector
Base implementation class for selectors.

This class encapsulates the low-level machinery required to implement the interruption of selection operations. A concrete selector class must invoke the begin and end methods before and after, respectively, invoking an I/O operation that might block indefinitely. In order to ensure that the end method is always invoked, these methods should be used within a try ... finally block:

    try {
        begin();
        // Perform blocking I/O operation here
        ...
    } finally {
        end();
    }

This class also defines methods for maintaining a selector's cancelled-key set and for removing a key from its channel's key set, and declares the abstract register method that is invoked by a selectable channel's register method in order to perform the actual work of registering a channel.

Since:
1.4