Java - Threads Question and Answer
Java - Threads Question and Answer
11. Which method registers a thread in a thread scheduler?
- run();
- construct();
- start();
- register();
12. Assume the following method is properly synchronized and called from a thread A on an object B:
wait(2000);
After calling this method, when will the thread A become a candidate to get another turn at the CPU?
wait(2000);
After calling this method, when will the thread A become a candidate to get another turn at the CPU?
- After thread A is notified, or after two seconds.
- After the lock on B is released, or after two seconds.
- Two seconds after thread A is notified.
- Two seconds after lock B is released.
13. Which of the following will not directly cause a thread to stop?
- notify()
- wait()
- InputStream access
- sleep()
14. Which class or interface defines the wait(), notify(),and notifyAll() methods?
- Object
- Thread
- Runnable
- Class
15. public class MyRunnable implements Runnable
{
public void run()
{
// some code here
}
}
which of these will create and start this thread?
{
public void run()
{
// some code here
}
}
which of these will create and start this thread?
- new Runnable(MyRunnable).start();
- new Thread(MyRunnable).run();
- new Thread(new MyRunnable()).start();
- new MyRunnable().start();