Which two statements are true? Deadlock will not occur if wait()/notify() is used a thread will resume execution as soon as its sleep duration expires. Synchronization can prevent two objects from being accessed by the same thread. The wait() method is overloaded to accept a duration. The notify() method is overloaded to accept a duration. Both wait() and notify() must be called from a synchronized context?
Answers
Thase are true statements
- Synchronization can prevent two objects from being accessed by the same thread.
- The wait() method is overloaded to accept a duration.
- The notify() method is overloaded to accept a duration
Answer:
Synchronization can prevent two objects from being accessed by the same thread.
Both wait() and notify() must be called from a synchronized context.
Explanation:
wait() and notify() are methods in Java used for inter-thread communication and are used in multi-threading programming. wait() method is used by a thread to tell the scheduler that it is willing to give up its current position in the CPU queue in order to wait for another thread to do something. notify() method is used by a thread to tell the scheduler that it has finished with a particular task and that another thread can now proceed.
The wait() and notify() methods must be called from a synchronized context in order to prevent multiple threads from accessing the same object simultaneously and potentially corrupting its state.
It is true that the synchronization can prevent two objects from being accessed by the same thread, but it does not guarantee that the Deadlock will not occur. Deadlock can occur if two threads are waiting for each other to release a lock and neither thread can continue.
In addition, it is not true that a thread will resume execution as soon as its sleep duration expires. The thread will only resume execution once it is scheduled to do so by the CPU scheduler. Also, the wait() method is not overloaded to accept a duration, but the sleep() method can be used to pause a thread for a specific duration. The notify() method does not have an overload to accept a duration.
More question and answers:
https://brainly.in/question/20830108
https://brainly.in/question/21793582
#SPJ3