File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads priority Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads priority" Watch "threads priority" New topic

threads priority

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 808

I have read in K&B book that once a thread get their priority it cannot be changed.
So what about that:

What priority does the thread have?
My guess: 10 (according to K&B book)

Henry Wong

Joined: Sep 28, 2004
Posts: 20538

I have read in K&B book that once a thread get their priority it cannot be changed.

A thread priority can be changed with the setPriority() method.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
*phew* I'd just written some code to test the "setPriority" behaviour and was worried about my understanding when I say the priority changing.

I guess K&B mean the JVM will not, for its own reasons, change the priority of a thread; they way it might, for its own reasons, yank a thread back to the Runnable pool or ignore "yield()".

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Tangentially related -and possibly outdated, applying to older JVM versions- I recall it being best practice not to change the priority of threads, because unpredictable and undesirable behavior might result. Sorry, I can't recall the details.
I agree. Here's the link:
subject: threads priority
It's not a secret anymore!