Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

SocketChannels NIO

Thread view: 
Andersen - 21 Jan 2006 15:25 GMT
Say I have a machine with high speed concurrent IO, if I use one thread
which uses NIO (for SocketChannels) with a Selector, would it not impair
the performance? What is the solution?

Can I mix NIO with ordinary blocking calls? Say the selector says there
is data on a channel, then I use blocking IO on that channel in a
different thread?
Stefan Schulz - 22 Jan 2006 19:52 GMT
I am not entirely sure about this, but i think you need to keep your
channel in nonblocking mode as long as it is registered with a
selector. However, if this really is your bottleneck, you can have one
(or several) threads on standbye, which get handed a channel once it
becomes readable, read as much data as possible, and then return to
standbye mode.
Thomas Hawtin - 23 Jan 2006 17:13 GMT
> I am not entirely sure about this, but i think you need to keep your
> channel in nonblocking mode as long as it is registered with a
> selector. However, if this really is your bottleneck, you can have one
> (or several) threads on standbye, which get handed a channel once it
> becomes readable, read as much data as possible, and then return to
> standbye mode.

One way of handling this is to copy from the channel into a
PipedOutputStream (or saner equivalent) in your main selector handling
thread. Then have worker thread work as traditional on the matching
InputStream.

This can be particularly effective with tasks such as web serving.
Connections will be idle most of the time. However bursts of activity
occur where traditional I/O may be significantly simpler.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

EJP - 23 Jan 2006 02:56 GMT
> Say I have a machine with high speed concurrent IO, if I use one thread
> which uses NIO (for SocketChannels) with a Selector, would it not impair
> the performance? What is the solution?

Why would it impair the performance? It would only mean that your
Selector would fire more frequently and the reads and writes would
execute more quickly.

> Can I mix NIO with ordinary blocking calls? Say the selector says there
> is data on a channel, then I use blocking IO on that channel in a
> different thread?

If you deregister the channel from the Selector you can put it into
blocking mode, but then if you really want to have different threads why
would you use NIO and a Selector at all?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.