• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NIO

 
Erwin Bredford
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i working on my developer exam i just want to know if
you are allowed to use the nio package that prevents blocking
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Though I think most of us are just using FileChannel, which has nothing really to do with the nonblocking functionality; it's just fast. (And maybe atomic, but that's a longer discussion.) If you use sockets though, you could make more direct use of the nonblocking functionailty if you wish.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
If you use sockets though, you could make more direct use of the nonblocking functionailty if you wish.

Mmh... I guess you didn't it on purpose, but it looks like you finally found a subject we could disagree on !
Now, seriously, I wondered if I could use SocketChannels or not, because Max wrote in his book that it could be a nice and direct way to automatic failure.
I didn't understand why it had to be so, so I posted the following thread in early September :
Sockets vs SocketChannels ?
I didn't get any answer but Andrew's one, and as Andrew is a wise guy, I accepted his arguments against SocketChannels without defending my own position.
It's now too late for me to refactor anything in the network area, but if you have a different opinion from Andrew's one, it would be interesting to know it (at least for my choices.txt file).
Writing that, I am aware that if you disagree with Andrew (unprobable), you'll disagree with Max too (much more probable ! ), and ... you'll agree with me once more , in which case we'll have to wait a bit more to find a topic we disagree on . ).
Best,
Phil.
PS:
1� How did Max to find so many subjects to argue with you so long ?!
2� When is Max coming back ? Still in December ? We miss him and your interesting discussions !
[ November 12, 2003: Message edited by: Philippe Maquet ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mmmm... I hadn't really thought much about sockets in a while; I had forgotten the instructions use of the term "simple sockets". How boring; pity. So yeah, it seems that SocketChannels are a bit too risky. Though I'd note that there's still some ambiguity in the phrasing, but it's probably not worth the risk. Oh well. My point though was that most NIO isn't "nonblocking" unless we specifically look at SocketChannels or other SelectableChannels. Which I guess we won't.
 
Vitaly Zhuravlyov
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,

Though I think most of us are just using FileChannel, which has nothing really to do with the nonblocking functionality; it's just fast.

Have you ever performed or seen any test showing that FileChannel really outperform RandomAccessFile in read mode? I ran a number of simple tests and they show that FileChannel in most cases is slower.
Cheers
Vitaly
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I guess I never compared them directly myself - not for a plain read(). I know that a had several bad experiences with RandomAccessFile under 1.2, where using it was much slower than using a stream, even for a random-access read. That is, for a single read() it was quicker to create a new FileInputStream and skip() to whatever offset I wanted, rather than use RandomAccessFile. So ever since then I just avoid RAF wherever possible. If it's no longer emabarrassingly slow in current JDKs, great. Do you happen to have the code for the tests you ran? I may run some tests of my own later, but I'd like to see what you have if possible.
 
Vitaly Zhuravlyov
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim, the code is not sophisticated at all. The "small" file is the data file from the assignment, the "big" file has 1000 similar records (180K).

I also ran a similar test for 10 different small files and 10 different big files. Well, not really different but with different names. And in this case FileChannel slightly outperformed RAF for big files.
I am really eager to hear that I'm wrong.
Vitaly
 
Erwin Bredford
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think there has been a divertion in this all topic .
i asked if it was ok to use nio in the exam.
and it brought about all this stuff about randomAccessFile
and filechannel.
could someone please answer me
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could someone please answer me
The answer was yes, in my first post. Yers, you can use NIO. As long as you aren't asking about "nonblocking" features, that's all you need to know.
Vitaly, that's interesting. There are a number of different ways to set things up here, so it's possible that FileChannel may be faster in some configurations. But it does seem that RAF is a lot faster than it was in 1.2 at least - that's good. Maybe I'll experiment more later to see if I can't find ways to make FileChannel work better. But your basic point seems good - at least in some setups, RAF can be faster than FileChannel. Thanks for pointing that out.
 
Vitaly Zhuravlyov
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim,
Looks like now and then we (or at least I) follow another motto: "For every simple problem, there is a solution that is complex, combersome, but correct" I've got my intial schema reading re-written from RAF to NIO to be "consistent" and hoping it performs better. Illusions are broken.
Vitaly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic