jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Another Java NIO stumble" Watch "Another Java NIO stumble" New topic

Another Java NIO stumble

Evgeni Dimitrov

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
I agree. Here's the link: http://aspose.com/file-tools
subject: Another Java NIO stumble
It's not a secret anymore!