14.04. Synchronization under concurrency control

Synchronization under concurrency control

  • Eclipse: Oxygen
  • Java: 1.8

Synchronization under concurrency control

Java synchronization is a concept where errors can appear in the code if the same entity is shared by two or more threads. Therefore, it can cause different results each time the execution takes place.

When we start two or more threads within a program, there may be a situation in which multiple threads try to access the same resource. Therefore, it is necessary to synchronize the action of several threads and make sure that only one thread can access the resource at a given time.
As you can see in the following program, that may or may not print a counter value in the sequence and every time it produces a different result based on the availability of the CPU for a thread.

Output

Contributed by: Poonam Tomar

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments