I'm doing a sort of event loop to process multiple non-blocking sockets in Java. The problem is that when I leave the loop untouched, it uses a whole core. (For instance, I have a quad core and everytime I start my program, the CPU jumps to 25% everytime.)
I know I could use Thread.sleep() to slow down the usage of processor but I was wondering if there's a proper way of doing that. I feel like Thread.sleep(1) might be limitating my event loop.
So my question is, how should I do it? Is there a proper way of doing that? Should I reduce the thread's priority? Should I use Thread.sleep(0, someNanosecondsAmount) ?