This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "threads" Watch "threads" New topic
Author

threads

winny dhar
Greenhorn

Joined: Nov 14, 2011
Posts: 13
hello..
can you please tell me what are race conditions and different ways to handle it??
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
hi winny - can you tell me what is a race condition?
winny dhar
Greenhorn

Joined: Nov 14, 2011
Posts: 13
basically race condition occurs when two or more process try to read and write on a shared data.. its caused due to deadlock..do you know how to handle this problem if occured??
rohit chavan
Ranch Hand

Joined: Oct 08, 2010
Posts: 131

winny, java has provided synchronization to tackle the RACE CONDITIONS, which means two (or more) threads are competing for a single resource. If the access is not mutually exclusive,( i.e. while one thread is updating/accessing a variable any other thread cannot acces/update the value of this particular variable), then this perticular resource would end up in having inconsistent state.

One at a time acces (i.e. synchronization) helps us overcome this problem.

Synchronization can be provided by different ways, e.g. using synchronized block or synchronized method. There are many links which have detailed explainations regarding these two approaches.

However if you have hit on any particular problem, post it, so that people can help you.

Mean while you can refer this link for detailed information.
Race Conditions and Mutual Exclusion
winny dhar
Greenhorn

Joined: Nov 14, 2011
Posts: 13
thanks rohit...
actually i was doing producer consumer problem using threads in which a race condition occurs ...so can i remove that race condition with synchronization and without synchronization both??
rohit chavan
Ranch Hand

Joined: Oct 08, 2010
Posts: 131

synchronization is the only way as per my knowledge, to tackle this situation.

Following code would help if you are particularly looking at prod-consumer problem.



Check it out, hope this will be helpful.
winny dhar
Greenhorn

Joined: Nov 14, 2011
Posts: 13
thanku rohit for this explanation..i got your point..
 
Don't get me started about those stupid light bulbs.
 
subject: threads
 
Similar Threads
How to convert xml to pdf form in java
WA #1.....word association
How to deploy/undeploy EJBs application through HOT Deployment on websphere 6.1?
can i deploy any ear/jar/war without admin console on websphere 6.1?
Happy New Year! Welcome to our new forums!