File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Another Java NIO stumble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Another Java NIO stumble" Watch "Another Java NIO stumble" New topic
Author

Another Java NIO stumble

Evgeni Dimitrov
Greenhorn

Joined: Dec 20, 2012
Posts: 2
I have a small server, which works under Windows and fails under Red Hat. The idea is:

- a main thread with a ServerSocketChannel and a Selector
- when it accepts a connection, it creates an Event with the SocketChannel in it
- the Event is offered to the Queue
- each Worker thread has its own Selector and a DB Connection
- the Worker thread takes the Event from the Queue, sets the Selector and the DB Connection in it and calls Event's method getProcessed
- the Event reads the SocketChannel (always fine), queries the DB (always fine) and writes to the SocketChannel (works under Windows and fails under Red Hat)

the code is:


I will appreciate any comments and suggestions.

When it fails under Red Hat the browser shows "The connection was reset". Although only twice (out of 50 attempts) I got the correct response under Red Hat - judging by the log - the Opera browser has tried 4 times in a row and eventually has got the response.

When it succeeds and when it fails, the log is always perfect:
1. limit::137
1. position::0
1. remaining::137
2. limit::137
2. position::137
2. remaining::0
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Another Java NIO stumble