Threading Model   «Prev  Next»


Java Multi-threading - Quiz

Each question is worth one point. Select the best answer or answers for each question.
 

1. Under which conditions may a waiting thread enter the ready state?
Please select all the correct answers.
  A. Its stop() method is invoked.
  B. Its interrupt() method is invoked.
  C. Its yield() method is invoked.
  D. Its wait() method is invoked.

2. When a thread blocks on I/O, which of the following are true?
Please select all the correct answers.
  A. The thread enters the running state.
  B. No other threads may perform I/O.
  C. The thread waits until the I/O operation is completed.
  D. The thread is given direct access to a system's I/O ports.

3. Which of the following occur when a thread invokes an object's wait() method?
Please select all the correct answers.
  A. The thread enters the running state.
  B. The thread causes the object to enter the waiting state.
  C. The thread enters the waiting state until it is notified.
  D. The thread gives up the object's lock.

4. Which of the following are true about the notify() and notifyAll() methods?
Please select all the correct answers.
  A. The notify() method is used to designate which thread should be notified.
  B. The notifyAll() method causes all threads that are awaiting notification from a particular object to enter the ready state.
  C. The notifyAll() method throws the NotifyException.
  D. The notify() method causes a single thread that is awaiting notification from an object to enter the ready state.

5. Which of the following lines of output are displayed by the following program?
class Example {

  public static void main(String args[]) {
    MyThread thread = new MyThread();
    thread.display("created");
    thread.start();
  }
}

class MyThread extends Thread {
  public void display(String s) {
    System.out.println(s);
  }

  public void run() {
    display("running");
  }

}

Please select all the correct answers.
  A. created
  B. The output will vary from one JVM to another.
  C. running
  D. The program will not display any output.

6. Which of the following thread state transitions are possible? Please select all the correct answers. (Select 2 options)
  A. From dead to running
  B. From running to dead
  C. From waiting to running
  D. From running to waiting

7. Which method causes a thread to transition from the running state to the ready state?
Please select the best answer.
  A. yield()
  B. suspend()
  C. wait()
  D. sleep()

8. Which of the following are true about locks?
Please select all the correct answers.
  A. A lock may be encrypted for extra security.
  B. A thread must acquire an object's key to open its lock.
  C. A thread must acquire an object's lock to execute one of the object's synchronized methods.
  D. A thread must be notified before it can acquire an object's lock.

9. Which of the following are thread states?
Please select all the correct answers.
  A. ready
  B. waiting
  C. scheduling
  D. time slicing

10. Which of the following conditions may keep a thread from running?
Please select all the correct answers.
  A. A thread is blocking on I/O.
  B. A thread is involved in an endless loop statement.
  C. A higher priority thread is executing.
  D. A thread acquires the lock on an object.

11. What is the relationship between an object's lock and its synchronized methods?
Please select the best answer.
  A. There is no relationship between an object's lock and its synchronized methods.
  B. Acquiring a synchronized method results in the execution of the object's lock.
  C. The synchronized methods are used to open the object's lock.
  D. The object's lock must be acquired before a synchronized method of the object may be executed.