Java Programming - Threads - Discussion
Discussion Forum : Threads - Pointing out the correct statements (Q.No. 6)
6.
Which statement is true?
Answer: Option
Explanation:
Option A is correct because the notifyAll() method (along with wait() and notify()) must always be called from within a synchronized context.
Option B is incorrect because to call wait(), the thread must own the lock on the object that wait() is being invoked on, not the other way around.
Option C is wrong because notify() is defined in java.lang.Object.
Option D is wrong because notify() will not cause a thread to release its locks. The thread can only release its locks by exiting the synchronized code.
Discussion:
4 comments Page 1 of 1.
Nikhil said:
4 years ago
@All.
When one thread is completely executed then another threads get notifications like wait() and notify() i.e notifyAll() to all thread.
When one thread is completely executed then another threads get notifications like wait() and notify() i.e notifyAll() to all thread.
Jaly said:
7 years ago
If all thread performing different task then there is no need to synchronized.
Raj said:
1 decade ago
If all thread performing different task then there is no need to synchronized.
Alexander Monakhov said:
1 decade ago
'notifyAll() must be called in synchronized context' is necessary but not sufficient. the thread must hold the lock on the call site.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers