Review Questions


graphics/rq_icon.gif
9.8

Which one of these events will cause a thread to die?

Select the one correct answer.

  1. The method sleep() is called.

  2. The method wait() is called.

  3. Execution of the start() method ends.

  4. Execution of the run() method ends.

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

  1. The first number printed is 13 .

  2. The number 14 is printed before the number 22 .

  3. The number 24 is printed before the number 21 .

  4. The last number printed is 12 .

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

  1. All lower priority threads will be granted CPU time.

  2. The current thread will sleep for some time while some other threads run.

  3. The current thread will not continue until other threads have terminated .

  4. The thread will wait until it is notified.

  5. None of the above.

9.11

Where is the notify() method defined?

Select the one correct answer.

  1. Thread

  2. Object

  3. Applet

  4. Runnable

9.12

How can the priority of a thread be set?

Select the one correct answer.

  1. By using the setPriority() method in the class Thread .

  2. By passing the priority as a parameter to the constructor of the thread.

  3. Both of the above.

  4. None of the above.

9.13

Which statements are true about locks?

Select the two correct answers.

  1. A thread can hold more than one lock at a time.

  2. Invoking wait() on a Thread object will relinquish all locks held by the thread.

  3. Invoking wait() on an object whose lock is held by the current thread will relinquish the lock.

  4. Invoking notify() on a object whose lock is held by the current thread will relinquish the lock.

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

  1. The code will fail to compile.

  2. Nothing special will happen.

  3. An IllegalMonitorStateException will be thrown if the wait() method is called while the current thread does not hold the lock of the object.

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

  1. The thread is waiting for some condition as a result of a wait() call.

  2. The execution has reached the end of the run() method.

  3. The thread is waiting to acquire the lock of an object in order to execute a certain method on that object.

  4. The thread does not have the highest priority and is currently not executing.

  5. The thread is sleeping as a result of a call to the sleep() method.



A Programmer[ap]s Guide to Java Certification
A Programmer[ap]s Guide to Java Certification
ISBN: 201596148
EAN: N/A
Year: 2003
Pages: 284

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net