Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another Java NIO stumble

 
Evgeni Dimitrov
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic