LINKS

Java Tutor Homepage

Java Applications and Components

Java Applets and Components

Java Frequently Asked Questions:
    1. What is Inheritance?
    2. What is Polymorphism?
    3. What is Encapsulation?
    4. Avoiding the Divide by Zero Error
    5. Public Classes in Java Source Files
    6. The Import Statement in Java
    7. Classes with Default Access
    8. What are Local Variables?
    9. What is an Abstract Method?
    10. Data Structures
    11. What is Autoboxing and Auto-Unboxing?
    12. What is multithreading?
    13. What are Threads?
    14. Thread States
    15. What is the Purpose of Synchronization?
    16. Thread Interaction
    17. Can You Start a Thread Twice?

Java FAQ 15 - What is the Purpose of Synchronization?

The purpose of Synchronization is to prevent threads from invoking the same methods on an object at the same time; if this were allowed to happen, it could corrupt the objects state. This could be very bad for your program.

An Example:

Consider a credit card reader machine. You slide your card through, follow a few steps, and have paid for your item(s). Now consider what might happen if you go to slide your card, are working your way through the steps, and someone else slides their card. It wouldn’t be good if the credit card reader started reading their card. Of course, credit card readers are designed to handle this problem, just like programs use synchronization to handle the problem of threads invoking the same method on an object.