Posts

Showing posts from December, 2025

Synchronization in java

            Synchronization is a method which makes the one thread can access the shared resource at a time. The shared resource can be a variable, object or methods. The shared data can be used effectively. Features: The features are given below. ·        Data integrity. ·        Thread safety is achieved. ·        Race condition is effectively handled. ·        It prevents data inconsistency . Let us create a synchronized block in java . Program: To create synchronization in java This program creates a class for thread which is “ Th_Sample ”. It has two methods “incre()” and “getIt()”. “incre()” method is used to increment the value. “getIt()” method gets the input value. Next, a main class is created as “ S_Sample ”. The object for Th_sample is created. Two thread objects are created. Each one has separate for loop to ...