aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads priority" Watch "threads priority" New topic
Author

threads priority

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

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)


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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.

Henry


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()".


SCJP6
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: threads priority