The difference between class synchronization and object synchronization understand the class and objects ----------------------------------- ----------------------- Class can have a set of instances (class object)
Object is just an instance (instance of class) ----------------------------------------- ------------------ Class level synchronization, guarantee all instance objects, synchronous low efficiency when using critical resources
Synchronization of the subject level, synchronization when using critical resources, just guarantees that different instances of synchronous classes in this object are not guaranteed ---------------------------------------------------------------------------------------------- -------------------------------- Synchronous example (object), using synchronous non-static methods . The method is private. Synchronized ..... Thined expanded synchronous non-static variables, non-static blocks
The method of synchronization is included in the synchronous static method. The method is private. Static synchronized .... This expansion synchronous static variable, static block
-------------------------------------------------- ---------- Note: Singleton in the pattern, easy to use the subject level synchronization ----------------------- ------------------------------------ Note: synchronized (this) is just an object level synchronization --- -------------------------------------------------- ------- Tip: An example of a class level synchronization private static string class_sync = "class_sync"; ... synchronized (class_sync) ------------------- -----------------------------------------