Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: Complete code examples of thread-per-connection blocking IO versus NIO?
    primarykey
    data
    text
    <p>Ok, I'm going crazy here. I have been rewriting the NIO code for my server, and running into some real headaches. The bottom line is that getting NIO "right" is very hard. Some people pointed me to the Rox tutorial at <a href="http://rox-xmlrpc.sourceforge.net/niotut/" rel="nofollow noreferrer">http://rox-xmlrpc.sourceforge.net/niotut/</a>, which seems to be on a good path, but is not as complete as I would like. For example, I need to know how to close a connection on the server side only after queued outgoing ByteBuffers have been sent. SocketChannel.close() is abrupt and can lose data if done prematurely. I also need to send large packets that are larger than the read ByteBuffer. The Rox code (nor any other code I've looked at) deals with this. There are also many places where it seems uncaught exceptions are not properly handled. In my tests there are some errors and it's not clear how to handle them properly given the complexity of NIO.</p> <p>Anyhow, as I try to solve these problems, more of the tricky subtleties show up, and it's getting quite complex. So I'm considering an entirely different approach. Many people are saying that NIO is highly error-prone and needlessly confusing and complex. They advocate using a "thread-per-connection" model that uses blocking IO where each socket connection is run on its own thread. This seems like a good idea, and would reduce the bottleneck on the front end by having one selector thread for all connections (as in NIO), at the expense of higher overhead (for the threads). This sentiment is echoed by posts such as <a href="http://paultyma.blogspot.com/2008/03/writing-java-multithreaded-servers.html" rel="nofollow noreferrer">http://paultyma.blogspot.com/2008/03/writing-java-multithreaded-servers.html</a> and <a href="http://mailinator.blogspot.com/2008/02/kill-myth-please-nio-is-not-faster-than.html" rel="nofollow noreferrer">http://mailinator.blogspot.com/2008/02/kill-myth-please-nio-is-not-faster-than.html</a></p> <p>The code should be simple compared to NIO, but I really want some example code to look at. I can't seem to find anything. The problem is that I don't think this "thread-per-connection blocking I/O" strategy has a better name that I can actually get good Google results for. Can anyone link me to some tutorials or simple examples to explain using this "older" method of I/O and scaling it up using a thread pool? Or have any other words of wisdom? Thanks very much!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload