• 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

Default priority of threads

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was taking a sample test from JQPlus. One question is:
If a Thread's priority is not specified explicitly then in gets a priority of Thread.NORM_PRIORITY
True / False.
I said true, But the answer is false.
But i am sure, a thread created without setting any priority gets a default priority of 5, which is Thread.NORM_PRIORITY.
Any help??
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Natchit,
I think you're right about that. This is from the Java API:


"static int NORM_PRIORITY
The default priority that is assigned to a thread"


 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Natchit/Hungson,
A thread inherits the priority value from its parent. When you create the first thread in your application, then it will get the default priority (i.e. Thread.NORM_PRIORITY). But if you change the priority of this thread with the setPriority() method, and create a new thread (child) from this one thread (parent), then the child thread will inherit the priority value of the parent thread.
-Peter
[This message has been edited by Peter Tran (edited February 01, 2001).]
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes peter is right , I had a question on one mock exam where they didn't specify that an exisiting thread exists and they say choose the most appropriate answer. So question goes like this. When thread is created what is the priority assigned to it ? So i answered NORM_PRIORITY but i said i was wrong. Explanation was what the peter said above , but why ? The question didn't state that they have a parent thread.
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from the Javadoc API regarding threads:


Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. Each thread may or may not also be marked as a daemon. When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.


-Peter
[This message has been edited by Peter Tran (edited February 01, 2001).]
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i would like to add theat besides inheriting the priority from the parent thread, there's another inheritance involved too. a daemon thread spawns daemon threads.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
natchit,
Your name does not comply with the Javaranch naming guidelines which can be found at http://www.javaranch.com/name.jsp please register again with a valid name.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic