Skip to content


A Good Java NIO Tutorial

One of the newer features of Java as of 1.4 is non-blocking IO, yet it’s very hard to find decent documentation about it or even a simple tutorial. NIO is a very powerful feature but easy to get wrong given it’s complexity. However, James Greenfield, an engineer for Amazon, recently announced that he’d put up a tutorial for NIO, including a lot of important details of using NIO with SSL.

Posted in Algorithms, Computer Science, Culture, Disciplines, Java, Languages, Tips, Hacks, & Tricks. Tagged with , , , , , .

5 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. cool, i’ve had to make use of NIO several time over the last few years, wish i’d seen that tutorial before. thanks.

  2. Funny you should blog about this. I’ve been spending a good deal of the last week trying to untangle NIO (the non-blocking networking part, not all the other stuff that NIO entails like memory mapping).

    I found that a pretty nice package has been moved into Apache called MINA. I’ve decided that I will most likely use this for our purposes. It was previously called Netty2. If you don’t feel like struggling with a poorly documented API unnecessarily, I’d consider it. MINA is still lacking documentation, too, but the mailing list is very lively, and the examples are pretty good.

    I’ve also read that under certain conditions/requirements, using BIO still wins out in performance. I’ll be darned if I remember where, but I think it was on Sun discussion boards, or maybe the IBM ones.

  3. Yeah, I have yet to actually dive into NIO myself, but a library I’m using at the moment is NIO based as well as some other stuff in the platform I work on, so it’s been on my radar lately.

  4. Yep. I dug into it when it was first released but I never understood the benefits fully back then. And how the world can documentation about such a nice piece of architecture as event driven communication (which bytw is hot hot hot in lighttpd, apache etc) be so crappy ?

    Anyway I think most tutorials only work in windows especially the thing that a key mostly is writeable in linux will make you to hack some workarounds to not have zillions of wakeups on write events.

    I will try this tutorial. I’m writing since 4 years (yet another) caching framework (which I will release on SF) and will include a nonblocking distributed server/client cache. I have a total well performing blocking solution with worker threads, traffic control etc but I want to measure the difference between a well implemented nonblocking solution compared to a blocking.

    It will not be easy since serialization is involved and I think I will be needing a bunch of worker threads handling send queues. People tend to say that you always should use one thread but I’m skeptic since
    the underlying operations might read a file, db or so=block.

    Everywhere I read people says Serialization=not NIO. but I know it can be done since I have a stupid echo serializing server now.

    Keep up the blogging about this issue I sure need it :)

    Kindly

    //Marcus

  5. bea said

    There is another good nio tutorial on java. net.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.