• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need understanding about Fig.9-4 in the K&B SCJP 6 book

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was going through the SCJP 6 book by Kathy & Bert as part of my SCJP 6 preps. I came across this Figure 9-4 in the Threads section (Chapter 9) of this book. Here the author talk about the concept of 'Race-condition' between threads.

I tried to understand how this illustration exemplifies the idea of a race-condition but in vain. I would greatly appreciate if any of you could throw some light on this figure.

Appreciate your help,
Hari
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch! TellTheDetails please, otherwise we can't help you! There is no concept called Race - Condition in Java Threads.
 
H Ejilane
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abimaran Kugathasan wrote:Welcome to JavaRanch! TellTheDetails please, otherwise we can't help you! There is no concept called Race - Condition in Java Threads.



There is one in computer science...Then again Java doesn't even understand the concept of 0xFF without turning it into an integer first. Go figure.
 
See Furst
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
H Ejilane
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.





Thanks See furst... You've showed me the light at the end of the tunnel.

The Thread Safe Classes section that you pointed out gave me a better understanding of race-conditions.

I appreciate your help very much.
 
reply
    Bookmark Topic Watch Topic
  • New Topic