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