Questions for: Threads
- start()
- wait()
- notify()
- run()
- terminate()
(1) and (4). Only start() and run() are defined by the Thread class.
(2) and (3) are incorrect because they are methods of the Object class. (5) is incorrect because there's no such method in any thread-related class.
Option C is correct. notify() - wakes up a single thread that is waiting on this object's monitor.
Discuss About this Question.
class X implements Runnable
{
public static void main(String args[])
{
/* Missing code? */
}
public void run() {}
}
Which of the following line of code is suitable to start a thread ?
Option C is suitable to start a thread.
Discuss About this Question.
- notify();
- notifyAll();
- isInterrupted();
- synchronized();
- interrupt();
- wait(long msecs);
- sleep(long msecs);
- yield();
(1), (2), and (6) are correct. They are all related to the list of threads waiting on the specified object.
(3), (5), (7), and (8) are incorrect answers. The methods isInterrupted() and interrupt() are instance methods of Thread.
The methods sleep() and yield() are static methods of Thread.
D is incorrect because synchronized is a keyword and the synchronized() construct is part of the Java language.
Discuss About this Question.
- Thread(Runnable r, String name)
- Thread()
- Thread(int priority)
- Thread(Runnable r, ThreadGroup g)
- Thread(Runnable r, int priority)
(1) and (2) are both valid constructors for Thread.
(3), (4), and (5) are not legal Thread constructors, although (4) is close. If you reverse the arguments in (4), you'd have a valid constructor.
Discuss About this Question.
Discuss About this Question.