Threads - Concepts - Sun Certified Java Programmer 310-065 - Lesson 40 | Java courses
In this video, will see how we can implement the Runnable interface, and the use of the sleep() method.
"
download the application please visit www.mrbool.com/player
Title: Threads - Concepts - Sun Certified Java Programmer
310-065 - Lesson 40
Duration: 16 minutes
Summary: In this video, we start our discussion of Threads. Thread is a
single unit of execution. Threads can be created by extending the Thread class
and overriding the run() method. Thread objects can also be created by calling
the Thread constructor that takes a Runnable argument. The first questions we
tackle help us understand the signature of the methods available, how we can
implement the Runnable interface, and the use of the sleep() method. This
method has to exist in a try/catch block. Finally, we see how we can
synchronize threads. By making the methods as synchronized, the threads will
get the lock of the 'this' object before proceeding.
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 5:53pm
Watch for synchronize on a primitive
This web pages has some good tips on Java Concurrency:
http://tech.puredanger.com/2009/01/28/java-concurrency-bugs-synchronize-object/
In the video for question 4 we are told that the synchronized method as it is presented in option C is incorrect. This is true, but is not explained very well. The issue here is that the synchronized block can not lock on a primitive value, such as an int. Technically, with the way the question is worded, the two private variables held by the class could be Integer objects, like in the class below.
public class Test
{
private Integer a;
private Integer b;
public int read(){synchronized(a){return a+b;}}
public void set(int a, int b){synchronized(a){this.a=a; this.b=b;}}
}
In this configuration, the read() method will work. However, in the set() method, because the synchronized block is locking on "a" as opposed to "this.a", it has to be referring to the int parameter passed in by the method, which means the code is incorrect.
Answer it
Mr.Bool Editor
4/19/2012 7:34pm
RE:
Matthew,send your review to the author of the video, soon, will contact
Answer it
Ayad
4/20/2012 1:25am
RE:
Hi Matthew,
Great feedback!
Unfortunately, as I mentioned in the other comment, I did not author the questions. If you notice in the videos I always give credits to the authors and making sure that readers know I did not author these questions.
The idea is that with some background, discussion, and feedback (like we are doing now :) ), readers will grasp the ideas and understand them better.
Keep up the good work.
Ayad
Answer it
Help us to improve! Give us your feedback: