Posts

Showing posts with the label synchronization

Object and instance are same things?

Object and instance are same things? While reading about synchronization, I read static synchronized method locked on class object and synchronized method locks on current instance of an object. I have confusion what is class object and instance of an object? Don't object and instance are same things? The class is like a recipe, an object instance is like a cake. You need the recipe to make a cake. You can make more than one cake. You need to synchronize on the recipe though, because otherwise you might add eggs when you should be frosting. Once the cake is made, you need to synchronize on it unless only one person is eating it. And that ends my cake metaphor. Because now I want cake. – Elliott Frisch Jul 1 at 6:33 3 Answers 3 For every class loaded ...