Is there a way in code to set the priority in which a program should run at? I looked in the system class and couldn't see anything but am not sure where else to look.
I have a small server program that is in an infinite loop to listen for connections along a certain port. It's for a chat thing I'm developing, but I know it doesn't need to be taking up 100% CPU time for this one little task (I have a few threads going so that it can process input and output and I start new threads every time for a client to talk). everything is working well for it so I'm just wondering if there's a way to tune down its priority if I want to run it as a more permanent server and use this computer for other stuff.
I know I can just go into the taskmanager and change it that way, just wondering if there is a way in code to do this.
I think those two articles slightly miss the point, as they're concerned with Java's thread priorities, but what's at stake here is the priority of the JVM process as a whole within the OS.
When I hear about a loop using 100% CPU time, the first thing I'm thinking is that there's active waiting going on. How about putting a "Thread.sleep(100)" in each loop iteration? Or is that too long for the server to wait between iterations?
Ping & DNS - updated with new look and Ping home screen widget
Joined: Jan 09, 2008
There was a lot of discussion of windows thread and processes versus java thread priorities in the javaworld article pointed to in the sun blog:
Since process priority is OS specific, and Java tries to be OS agnostic, I would think you need to solve this problem separately for each OS you are on.
Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Joined: Nov 02, 2007
I'll look into it.
I am not running the server's listening command off a thread but I can easily do that. But yeah, I am looking at it at the OS level rather than at the thread. [ March 18, 2008: Message edited by: Christopher Young ]