Menu

#5 Lower CPU usage when socketMap is empty

open
nobody
None
5
2005-08-19
2005-08-19
Anonymous
No

I don't know if I'm using Raining Sockets wrong, but
when I tell it stopWhenIdle(false) and there are no
open connections, NioSocket uses 100% CPU while it sits
in a loop poll()ing. I made this little modification
to poll(timeout) and in the spirit of the LGPL I'm
releasing it...

replace:

if(socketMap.isEmpty())
return;

with:

if (socketMap.isEmpty()) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
return;
}

-- Daniel Gies
dfgies@gmail.com

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.