Java library provides a rich set of API methods to control the behavior of a thr
ID: 3841950 • Letter: J
Question
Java library provides a rich set of API methods to control the behavior of a thread. For example, we can specify when a thread will start, when exactly a thread can put into the sleep state, and when a thread will terminate. True False Assume the following method is properly synchronized and called from a thread Aon an object B: After calling this method, when will thread A become a candidate to get another turn at the CPU? After the lock on B is released, or after two seconds After object B is notified, or after two seconds Two seconds after object B is notified Two seconds after lock B is released Which method represents the best approach to generating a random number between one and ten if the methodExplanation / Answer
71. True
Yes, java provides the APIs to control the behavior of a thread. we use run() / start() method of a thread to start it. Java provides sleep(..) method to put it into sleep state. It also provides APIs to stop the threads in a co-operative way.
72. b. After object B is notified or after two seconds
wait() on a object, causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object.
The above code causes the thread A, to go into sleep mode, and wait until other thread invokes notify() or till 2 seconds. The main difference between sleep() and wait(), is that wait releases the lock on the object, where as sleep doesn't release the locks.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.