• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting a priority

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this help?

http://www.science.uva.nl/ict/ossdocs/java/tutorial/java/threads/priority.html

or perhaps this:

http://forum.java.sun.com/thread.jspa?threadID=647099&messageID=3809986
[ March 18, 2008: Message edited by: Bob Good ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bob Good
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

http://www.javaworld.com/javaworld/jw-09-1998/jw-09-threads.html

It also discusses differences on Solaris etc.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Christopher Young
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm.

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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic