Login:  Password:    
forgot my password
sign up!
Search: 
 
  This post is part of:
    Online course(s):   
 Sun Certified Java Programmer 310-065

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.

Replacing the StringBuilder (which is not thread safe, see http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/StringBuilder.html) with StringBuffer (which is thread safe, see http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/StringBuffer.html) would mean that multiple threads could read and write to the contents object concurrently, but there is no guarantee that the sequence of append statements in the log() method would always be called in the order in which they are shown. One thread could append 2 lines, a second thread could append some lines, and the results would be garbled.

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:
Give your note to the technical content
10 9 8 7 6 5 4 3 2 1
Give your note to the post's learning
10 9 8 7 6 5 4 3 2 1
Is this post helpful?
Yes No


Ayad Boudiab
Experience: A total of 10 years experience in developing applications using C++, Java, C#, ASP.NET, and SQL Server. In addition to 6 years experience in teaching programming courses at a local college. Degree: B.S. Computer Science Location: Atla...


Go to author's Space


Post stats:
Favorited:
 0

Post actions:
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 2,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 1,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,33
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits








mrbool.com
contact us   |   publish your post   |   buy credits

Copyright 2012 - all rights reserved to www.web-03.net