| 9.8 | Which one of these events will cause a thread to die? Select the one correct answer. -
The method sleep() is called. -
The method wait() is called. -
Execution of the start() method ends. -
Execution of the run() method ends. -
Execution of the thread's constructor ends. |
| 9.9 | Which statements are true about the following code? public class Joining { static Thread createThread(final int i, final Thread t1) { Thread t2 = new Thread() { public void run() { System.out.println(i+1); try { t1.join(); } catch (InterruptedException e) { } System.out.println(i+2); } }; System.out.println(i+3); t2.start(); System.out.println(i+4); return t2; } public static void main(String[] args) { createThread(10, createThread(20, Thread.currentThread())); } } Select the two correct answers. -
The first number printed is 13 . -
The number 14 is printed before the number 22 . -
The number 24 is printed before the number 21 . -
The last number printed is 12 . -
The number 11 is printed before the number 23 . |
| 9.10 | What can be guaranteed by calling the method yield() ? Select the one correct answer. -
All lower priority threads will be granted CPU time. -
The current thread will sleep for some time while some other threads run. -
The current thread will not continue until other threads have terminated . -
The thread will wait until it is notified. -
None of the above. |
| 9.11 | Where is the notify() method defined? Select the one correct answer. -
Thread -
Object -
Applet -
Runnable |
| 9.12 | How can the priority of a thread be set? Select the one correct answer. -
By using the setPriority() method in the class Thread . -
By passing the priority as a parameter to the constructor of the thread. -
Both of the above. -
None of the above. |
| 9.13 | Which statements are true about locks? Select the two correct answers. -
A thread can hold more than one lock at a time. -
Invoking wait() on a Thread object will relinquish all locks held by the thread. -
Invoking wait() on an object whose lock is held by the current thread will relinquish the lock. -
Invoking notify() on a object whose lock is held by the current thread will relinquish the lock. -
Multiple threads can hold the same lock at the same time. |
| 9.14 | What will be the result of invoking the wait() method on an object without ensuring that the current thread holds the lock of the object? Select the one correct answer. -
The code will fail to compile. -
Nothing special will happen. -
An IllegalMonitorStateException will be thrown if the wait() method is called while the current thread does not hold the lock of the object. -
The thread will be blocked until it gains the lock of the object. |
| 9.15 | Which of these are plausible reasons why a thread might be alive , but still not be running? Select the four correct answers. -
The thread is waiting for some condition as a result of a wait() call. -
The execution has reached the end of the run() method. -
The thread is waiting to acquire the lock of an object in order to execute a certain method on that object. -
The thread does not have the highest priority and is currently not executing. -
The thread is sleeping as a result of a call to the sleep() method. |