selector.select() in NIO and high cpu usage

A

Arandil

Hello,

I have a 'little' problem with Selector.select() method. I was using NIO in
my app successfully till the time I had to connect to about 50 hosts
simulateously... Everything works, but every thread I use to wait for data
from remote host is using very much CPU (even when no data is being transfered).
I used profiler to find out which method is faulty. I found out, that my problem
is in Selector.select() method. It is taking almost all available CPU power,
no matter if there is any data waiting...

Is there any way to reduce the CPU load to the minimum or do I have to use
other method than Selectors?

Thanks in advance and best regards,
Arandil.
 
A

Arandil

Is there any way to reduce the CPU load to the minimum or do I have to use
other method than Selectors?

Mea culpa, my fault... Profiler did say that select() was taking whole CPU load,
but that's not true... Indeed, there was a loop, but it was caused by my
overlooking of the problem - I had a loop, which was appending every bytebuffer
into one byte array (when there were more than one). It was looping, when
read() function didn't return 0. And this is the fault - n != 0, not n > 0...
Forgot about -1 (end of stream) :/

Sorry for garbage, and not cancelling to get this post to google - maybe
someone will need it one day...

Best regards, Arandil.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top