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 Thread priorities and Daemon threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread priorities and Daemon threads" Watch "Thread priorities and Daemon threads" New topic

Thread priorities and Daemon threads

Divya Eknath

Joined: Jul 27, 2006
Posts: 9
I ran the program below and got option(C) as the output but is this the only possible output?Are the thread priorities guaranteed to be considered?

What are the possible outputs of above program?
a) A Done
b) B Done
c) A Done B Done
d) B Done A Done
e) java doesnt support this type....
[ July 29, 2006: Message edited by: Barry Gaunt ]
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
thread priorities are not guaranteed different Jvm 's have different thread priorities so dont not rely on thread priorities.
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

When you use the max and min priorities the chaces that "a" will execute first are more. However the JVM may decide to interrupt your "a" thread thus making "b" to print out first.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please surround formatted code with tags - many people will not bother to read it otherwise. I will edit your original topic this time.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: Thread priorities and Daemon threads
It's not a secret anymore!