java.NIO + select + Network Interface Down = 100% CPU Usage

P

Peter Carter

hi all.

I'm having a problem with the java.nio package.
I've written a package that encapsulates java.nio and makes it usable.

However, there's a small bug. The classes work fine, however, when I
create a new ServerSocketChannel and bind on a port, leave it running
(at this point it works fine, it accepts connections & all).
Now, if I open the Network Connections window, and down one of my
network interfaces, the cpu usage rises up to 100%.
This is because the select() method no longer blocks and returns 0 all
the time... how strange.

Now, I have tried this with JDK 1.4.2_03 and 1.5: same result. I've
tried this on a Win2k server box, same result ... and on my WinXP
development machine.

The reason I'm downing my network interfaces is because this started
to happen on a computer that has a dial-up connection. Now whenever
the dial-up interface was killed, javaw.exe's process would rise up to
100% cpu.

I also looked around the forum and found an interesting post on the
Sun Forums: Taming the NIO circus, or something. They had java.nio
code, I tried it out. The code seemed to have the same problem as
mine... So I'm guessing that it might be a bug in the JVM...
Anyway, their solution was simple, if select returns the value "0" ten
times, the program exits.

It might be an acceptable solution for a test program, but its no
solution here.

Is there any way to fix this?

Thank you for your time.
 
B

Bill Scott

[email protected] (Peter Carter) wrote in message news: said:
The reason I'm downing my network interfaces is because this started
to happen on a computer that has a dial-up connection. Now whenever
the dial-up interface was killed, javaw.exe's process would rise up to
100% cpu.

I also looked around the forum and found an interesting post on the
Sun Forums: Taming the NIO circus, or something. They had java.nio
code, I tried it out. The code seemed to have the same problem as
mine... So I'm guessing that it might be a bug in the JVM...
Anyway, their solution was simple, if select returns the value "0" ten
times, the program exits.

It might be an acceptable solution for a test program, but its no
solution here.

Is there any way to fix this?


When you hit the "spinning" (after more than 10 useless wakeups)
rebuild the selector. Note that the same problem can be simulated by
pulling the network plug from a Win2k box.

Rebuilding the selector means gathering all keys from the existing
selector, storing them in a temp collection (w/ their interest set),
creating a new selector, and re-adding the old channels. Bit of a
pain, but it'll work for your situation. Note that I'd use a number
higher than "10" for your "time to rebuild" threshold.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top