Posts

Showing posts with the label Synchronization

Synchronization in Java

Image
Overview Synchronization is the process by which we control the accessibility of multiple threads for a particular resource. With synchronization only one thread at a time can execute a particular method or block of code. Without synchronization we can face the problem of data inconsistency and thread interference.  Disadvantages of Synchronization Synchronization can increase the waiting time of application due to synchronization of multiple threads. At times, synchronization can create performance issues. Types of Synchronization Process Synchronization - not present in Java multithreading. Thread Synchronization -  Mutual Exclusive - It can be achieved by 3 ways By synchronized method synchronized void bookSeats ( int seats) { if (seats <= total_seats ) { System. out .println(seats + " seats are booked successfully!!!" ) ; total_seats = total_seats - seats ; System. out .println( "Seats left: " + total_seats ) ; } else { ...