Threads - Analyzing exam questions - Sun Certified Java Programmer 310-065 - Lesson 41 | Java courses
In this video, a running thread may enter a blocked/waiting state by calling wait(), sleep(), or join().
"
download the application please visit www.mrbool.com/player
Title: Threads - Analyzing exam questions - Sun Certified Java Programmer 310-065 - Lesson 41
Duration: 17 minutes
Summary: In this
video, we continue our discussion of threads. A running thread may enter a
blocked/waiting state by calling wait(), sleep(), or join(). The reason it
enters that state is that it cannot acquire the lock for a synchronized block
of code. The wait method can take the number of milliseconds to wait (for
example, 2000 milliseconds, or 2 seconds). The notifyAll() method must be
called from a synchronized context. When a thread is waiting as a result of
wait(), it releases its lock. In order to ensure the instances of a class can
be safely used by multiple threads, we need to synchronize the public methods.
If a piece of code does not acquire a lock on t before calling t.wait(), it
throws IllegalMonitorStateException.
Methodology of the development of example: Good coding standard and simplified design to
prepare for the Java programmer certification exam CX-310-065.
Technology Used: Java - Core Concepts.
Keywords: class,
object, Thread, start(), run(), Runnable, sleep(), join(), wait(), notify(),
notifyAll().
Add a comment!
[Fechar]
Este post é fechado - você precisa ter acesso ao post para incluir um comentário.
Matthew Casperson
4/19/2012 8:5pm
Further explanation of Question 8
The explanation of question 8 is a bit vague.
Synchronizing the log() method only could lead to the getContents() method being called while a thread is in the middle of appending a string to the contents object. With a StringBuilder, the results would be unpredictable. With a StringBuffer, you might see half a log message being printed out.
Synchronizing the getContents() method only could lead to the log() method being called while the thread is dumping the contents object. Again, with a StringBuilder the results of this concurrent access would be unpredictable.
Answer it
Mr.Bool Editor
4/24/2012 1:30pm
RE:
We have forwarded your comment to the author.
soon, he will contact.
Answer it
Ayad
4/25/2012 7:38am
RE:
Thank you for the feedback Matthew.
Answer it
Help us to improve! Give us your feedback: