Option B is wrong. wait() causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
Option C is wrong. Methods of the InputStream class block until input data is available, the end of the stream is detected, or an exception is thrown. Blocking means that a thread may stop until certain conditions are met.
Option D is wrong. sleep() - Causes the currently executing thread to sleep (temporarily cease execution) for a specified number of milliseconds. The thread does not lose ownership of any monitors.
Option A and D are incorrect because they are narrowing the access privileges i.e. package(default) access is narrower than public access.
Option C is not method in the Runnable interface therefore it is incorrect.
Option A is wrong. The run() method of a thread is like the main() method to an application. Starting the thread causes the object's run method to be called in that separately executing thread.
Option B is wrong. There is no construct() method in the Thread class.
Option D is wrong. There is no register() method in 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.
(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.
Option B, C, and D are incorrect because they do not define these methods. And yes, the Java API does define a class called Class, though you do not need to know it for the exam.
Option B is wrong. The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
Option C is wrong. The stop() method is deprecated. It forces the thread to stop executing.
Option D is wrong. Is the main entry point for an application.
wait(2000);
After calling this method, when will the thread A become a candidate to get another turn at the CPU?
Option B is incorrect because a waiting thread will not return to runnable when the lock is released, unless a notification occurs.
Option C is incorrect because the thread will become a candidate immediately after notification, not two seconds afterwards.
Option D is also incorrect because a thread will not come out of a waiting pool just because a lock has been released.
Option A is wrong. There is no init() method in the Thread class.
Option C is wrong. The run() method of a thread is like the main() method to an application. Starting the thread causes the object's run method to be called in that separately executing thread.
Option D is wrong. The resume() method is deprecated. It resumes a suspended thread.
Option B is wrong. notify() - wakes up a single thread that is waiting on this object's monitor.
Option C is wrong. notifyAll() - wakes up all threads that are waiting on this object's monitor.
Option D is wrong. Typically, releasing a lock means the thread holding the lock (in other words, the thread currently in the synchronized method) exits the synchronized method. At that point, the lock is free until some other thread enters a synchronized method on that object. Does entering/exiting synchronized code mean that the thread execution stops? Not necessarily because the thread can still run code that is not synchronized. I think the word directly in the question gives us a clue. Exiting synchronized code does not directly stop the execution of a thread.
Comments
Copyright ©CuriousTab. All rights reserved.
Life