Thursday 27 June 2013

What is Race Condition in java? (or) How does Race condition occur in java?


  • Race condition in java is a type of concurrency issue caused in our program because of parallel execution of multiple threads.
  • A race condition occurs when two or more threads can access shared data and they try to change it at the same time i.e. both threads are "racing" to access/change the data.
  • Because the thread scheduling algorithm can swap between threads at any time, you don't know the order in which the threads will attempt to access the shared data. 
  • Since Java is a multi-threaded programming language hence risk of Race condition is higher in Java which demands clear understanding of what causes a race condition and how to avoid that.

No comments:

Post a Comment