AsynchronousByteCharChannel and Timeouts
Alan Bateman
Alan.Bateman at oracle.com
Tue Jul 13 06:40:48 PDT 2010
cowwoc wrote:
> Put it another way: how would you implement an efficient read-with-timeout on
> top of the current AsynchronousByteChannel interface? Alternatively, how
> would you implement read-with-timeout on top of an OS that only supports
> read-forever?
>
> I'm not looking for a full-fledged implementation. Just tell me what you
> would do conceptually.
>
I'm not sure that I have all the context here. When you say that the OS
only supports read-forever then it sounds like you are implementing
AsynchronousByteChannel via blocking operations - is that right? If so,
then you could use a ScheduledThreadExecutor to implement the timeout.
The issue then becomes what to do with the thread that is blocked doing
the I/O. Do you have a means to cancel/interrupt it? At least with
socket channels, then the channel will typically be closed if there is a
timeout because the peer is not responding.
-Alan.
More information about the nio-discuss
mailing list