boolean completed = false;
try {
begin();
completed = ...; // Perform blocking I/O operation
return ...; // Return result
} finally {
end(completed);
}
The completed argument to the {@link #end end} method tells
whether or not the I/O operation actually completed, that is, whether it had
any effect that would be visible to the invoker. In the case of an
operation that reads bytes, for example, this argument should be
true if, and only if, some bytes were actually transferred into the
invoker's target buffer.
A concrete channel class must also implement the {@link
#implCloseChannel implCloseChannel} method in such a way that if it is
invoked while another thread is blocked in a native I/O operation upon the
channel then that operation will immediately return, either by throwing an
exception or by returning normally. If a thread is interrupted or the
channel upon which it is blocked is asynchronously closed then the channel's
{@link #end end} method will throw the appropriate exception.
This class performs the synchronization required to implement the {@link
java.nio.channels.Channel} specification. Implementations of the {@link
#implCloseChannel implCloseChannel} method need not synchronize against
other threads that might be attempting to close the channel.