Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NIO to implement the data reading/writing

 
Rod Abreu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it allowed to use NIO to implement the data reading/writing on server DB?
Is it a good idea?
Is there any other better possibility?

Many thanks,
Rod
 
Sean Gildea
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod,

I recall a thread specifically saying that NIO was prohibitted or borderline questionable to use so I would suggest you stay clear of using it and stick with the defacto acceptable IO standard for the exam, RandomAccessFile.

Good luck
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun's web page for the exam specifically prohibits NIO. That tells me that if I use it I automatically fail.

Can you guess whether NIO is in my design...
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has been a topic of debate for some time. Despite what Sun's website says, several people have contacted Sun through the who2contact@sun.com address and asked about NIO. Sun's response has been that you can use NIO as long as the instructions you downloaded do not specifically forbid it. Check out this thread for Andrew's take on it.

If you are still a little unsure about NIO, and really want to use it in your assignment, email Sun yourself, and include their response in your choices documentation.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I sent them an e-mail today. I'm very interested to see what they say, because the same section that bans NIO bans other technologies too. Their response could alter my networking layer (for the better!).

Interestingly, while my instructions do not explicitly ban NIO, they do state that I have only two choices for networking, sockets or RMI. Hmm.
[ January 19, 2005: Message edited by: Jeff Bosch ]
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To reiterate what I said in a previous thread about NIO. Even if Sun says you can use it, this is a bad choice for networking since it provides nothing of benefit to this assignment and actually gets in the way.

Maturity:

Even though its similar to the time honoured way to code sockets in Unix C, NIO is not dependable in JDK 1.4, it gets close by 1.4.2 and appears to work properly in 1.5. There are lots of pitfalls, especially for those who are not familiar with non-blocking socket I/O. If you don't believe me read the bug parade and the NIO messages on the Sun Java Forum.

Threading:

Lots of fun and games here. NIO non-blocking I/O works best in a single thread. The main advantage of the non-blocking I/O is that you won't need all those threads. But if you need them anyway, expect problems. See the comments about register() and interestOps(). You need a queue to deal with these.

Object Serialization:

NIO is not stream oriented, so you can't wrap an ObjectInputStream around it, there is a way, but you lose the non-blocking mode, so its hardly worth it. You will need to build a means of sending a serialized object or define a protocol that can transfer an array of character strings as a single byte array. Fun if you are into that sort of thing, but much more difficult than using ObjectInputStream, stream oriented sockets and thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic