|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Abimaran Kugathasan wrote:Welcome to JavaRanch! TellTheDetails please, otherwise we can't help you! There is no concept called Race - Condition in Java Threads.
Doin' Java to be one of the cool kids.
I usually use Perl;
H Ejilane wrote: Ok, let me phrase it this way.
I found the following para in Kathy & Bates' SCJP Sun Certified Programmer for Java 6 Exam 310-065 book.
Reference :
Page no. 733,
Chapter : 9 - Threads,
Section : Synchronizing code
The passage goes like this,
The problem is known as "race condition," where multiple threads can access the same resource (typically an object's instance variables), and can produce corrupted data if one thread "races in" too quickly before an operation that should be "atomic" has completed.
Now starts my question. Just above this para there is a figure that illustrates a race-condition scenario. So Im not able to correlate this picture with the above definition. So I was just wondering if someone on the floor had an understanding and would share his thoughts.
Hope this gives an clearer understanding of my problem.
See Furst wrote:
H Ejilane wrote: Ok, let me phrase it this way.
I found the following para in Kathy & Bates' SCJP Sun Certified Programmer for Java 6 Exam 310-065 book.
Reference :
Page no. 733,
Chapter : 9 - Threads,
Section : Synchronizing code
The passage goes like this,
The problem is known as "race condition," where multiple threads can access the same resource (typically an object's instance variables), and can produce corrupted data if one thread "races in" too quickly before an operation that should be "atomic" has completed.
Now starts my question. Just above this para there is a figure that illustrates a race-condition scenario. So Im not able to correlate this picture with the above definition. So I was just wondering if someone on the floor had an understanding and would share his thoughts.
Hope this gives an clearer understanding of my problem.
First of all you have to understand that the main problem with the diagram is that it doesn't really represent time too well...
Imagine that instead of next to each other.. the threads are one above the other as time progresses from left to right. Now imagine that at one point in time A and B are pointing to object one... At the next position in time A points to two and B point to one and then the next A and B are both pointing to object two... The race condition occurs between time periods two and three where B does something to object two that A depended on before A was finished with the data in object two, but B "raced in" and changed things before A was done with it's operation. This means that A is dealing with corrupt data.
There is a better example with StringBuffer on page 742 in the Thread Safe Classes section.