my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread practice exam question doubt 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 practice exam question doubt" Watch "Thread practice exam question doubt" New topic

Thread practice exam question doubt

David Samer
Ranch Hand

Joined: Feb 08, 2012
Posts: 49

Hello everyone.

I am not having clear at all one of the answer regarding to a practice test from Kathy's and Bert's practice exams book, first question, page 57.

Here the question:

Which are true?
A) Compilation Fails.
B) An exception is thrown at runtime.
C) Bang will execute for a second or two.
D) Bang will execute for at least 10 minutes.
E) Thread t1 will almost certainly be the last thread to finish.
F) Thread t1 will almost certainly be the first thread to finish.
G) It's difficult to predict which thread will be the last to finish.

The correct answers are C and G. I have clear G one but not C. Which is the way to know such as assumption? . Thanks in advance.

Wesleigh Pieters
Ranch Hand

Joined: Sep 04, 2012
Posts: 81
because line 21 will be called at some point
Ankit Gareta
Ranch Hand

Joined: Mar 28, 2011
Posts: 67

Hi David,

Thread's sleep method is static,so t1.sleep() means only the current thread that's executing will go to sleep..

In this example, all 3 thread will execute and all 3 will go to sleep at their i's value reach to 250 once, and sleep to 600 milliseconds after 600 milliseconds they will executing remaining for loop.
Now it can be possible that they all can execute within 1 sec or little more..(can't say exactly).
but as options said it's possible to finish within that time, but not as 10 minutes (Its too long time to finish).

hope that will help,


OCPJP 6 (91%)
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 1118
In the worst case scenario, t1, t2 and t3 execute sequentially. The scheduler let one thread complete before another one start. This is the worst case.
In this worst case scenario, t1 sleeps for 600 ms , completes. Then, t2 sleeps for another 600 ms, and completes. Lastly, t3 sleeps for another 600 ms and completes.

600ms*3 = 1800ms.

The total execution time for Bangs is at least 1800ms + the time to execute the loop.
So, two seconds may be one of the answers.
David Samer
Ranch Hand

Joined: Feb 08, 2012
Posts: 49

Thank makes sense now. Thank you to the 3 of you , help much appreciated.
I agree. Here's the link:
subject: Thread practice exam question doubt
It's not a secret anymore!