This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

threads  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello..
can you please tell me what are race conditions and different ways to handle it??
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi winny - can you tell me what is a race condition?
 
winny dhar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 133
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanku rohit for this explanation..i got your point..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!