Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Thread Exercise Question... Phil Heller book

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which one statement is always true about the following application

clas HiPri extends Thread
{
HiPri()
{
setPriority(10);
}

public void run()
{
System.out.println(�Another thread starting up�);
While(true) {}
}

public static void main (String args[])
{
HiPri hp1 = new HiPri();
HiPri hp2 = new HiPri();
HiPri hp3 = new HiPri();
hp1.start();
hp2.start();
hp3.start();
}
}

A.When the application is run, thread hp1 will execute, threads hp2 and hp3 will never get the cpu
B.When the application is run,thread hp1 will execute to completion, thread hp2 will execute to completion, then thread hp3 will execute to completion
C.When the application is run, all three threads(hp1,hp2,hp3) will execute concurrently, taking time sliced turns in the cpu
D.None of the above scenarios can be guaranteed to happen in all cases.

The answer I choose was D but author says C. pls explain�.
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the copy of the book I have, the same question is posed, but with only answers

A. When the application is run, thread hp1 will execute; threads hp2 and hp3 will never get the CPU.
B. When the application is run, all three threads (hp1, hp2, and hp3) will get to execute, taking time-sliced turns in the CPU.
C. Either A or B will be true, depending on the underlying platform.



The answer given is C for the usual reason (platform independence). I don't know what edition this is, as it doesn't say on the cover or in the front matter, but it is The Complete Java 2 Certification Study Guide (Roberts, Heller, Ernest) from Sybex 1999.

Maybe Mr. Heller can give us an insight?
 
Rupak Khurana
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the 5th edition which is the latest, April 2005. I guess the question was revised but not its answer.

Well here is whats mentioned in the answers section of the book..

"C. There is no way to predict how thread priority manipulation will affect the specific performance of individual threads. Priority Manipulation only affects overall statistical behavior."
[ July 11, 2005: Message edited by: Rupak Khurana ]
 
Timmy Marks
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well there you have it, it appears the answer should be D. The nature of the explanation shows that C is not right.

I'm going to say mine is probably a first edition (I think other editions would say it on there), it is terribly old, but it got me through certification with no other preparation (albeit, that was quite a while back).
reply
    Bookmark Topic Watch Topic
  • New Topic