views:

168

answers:

2

The Java NIO Socket Framework supposedly hides the dirty details of non-blocking IO from developers, allowing them to build highly scalable applications, which can handle over 10000 incoming and outgoing sockets using only one thread.

  • Are non blocking IOs still a pain with the typical version of Java 2 SE/EE?

  • Is this framework still necessary and useful?

Thanks for your time.

+3  A: 

Well, NIO creates an abstraction over some of the details, certainly. Non-blocking IO is still a pain to get your head around (at least, I find it is) but at least it's feasible. (Personally I prefer the .NET style of asynchronous IO, but that's a different matter.)

I usually use blocking IO: for most tasks, this is all I require and I wouldn't gain significantly by using non-blocking IO. In some cases (such as the one you mentioned) non-blocking IO is really the only way forward if you want to keep your thread down.

I recommend that you learn about it, play with it, and then use judgement to decide when to use it in production code. I wouldn't suggest starting to use it everywhere...

Jon Skeet
+1  A: 

Yes, NIO is very useful. NIO is also a bit hard to work with. Depending on your needs you could consider using frameworks that wrap NIO, like grizzly or mina. Grizzly is the networking part of glassfish appserver from sun. mina is a network application framework from Apache.org.

Personally I prefer grizzly but that's just me.

Erik