[java.nio] Blocking mode for a while - How ?

X

xEM

I'm using selector to manage connection on server. When server get an
incomming connection register this connection in non-blocking mode for
making readiness selection on it. In some moment i want to operate
with clients channels with blocking mode... but i can't change channel
to blocking mode, because is registered with selector in non-blocking
mode - i get IllegalBlockingModeException. How can i operate for a
while in blocking mode, but not to lose possibility readiness
selection on channel?
 
H

HDSkiFreak

GReetings:

if your channel inherits from an AbstractSelectableChannel (all
sockets do), then you can use the call:

Object mutex = channel.blockingLock()
and wrap your blocking sections in a synchronized segment using the
returned mutex object.

Look at the NIO guide, or check out the O'Reilly NIO book for
examples. You can also try google'ing the API call for some examples.

Best Regards,

HDSkiFreak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top