Java Synchronize

The important concept of threads, in any language, is synchronization. Synchronization plays an important role when multiple threads access the same data source. For example, one bank account can be accessed by all the partners of a business as it is a joint account. Here programmer should be very careful in his multithreaded program. To the rescue, Java comes with synchronize keyword. A method or block of statements can be synchronized. Synchronization avoid data inconsistency. A synchronized program becomes thread-safe code.

Synchronization, its English meaning is, to place the events in an order or to do the jobs in a sequence (order). Generally, one thread acts one source of data at a time like your thread acts on your account. There may be sometimes when two threads acts on one source data. The result is the possibility of data inconsistency. This is avoided with synchronization. Here we use, synchronize access modifier.

Following program gives all the details of synchronization.

Synchronization and Deadlock

For all programs on multithreading

Multithreading at a Glance

Leave a Comment

Your email address will not be published.