Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Java class level lock and object level lock are two different ways of locking in Java programming.

A Java class level lock is a lock on the entire class and is acquired by using the "synchronized" keyword on a static method or a static block. This lock prevents any other thread from accessing any synchronized static method or block of the same class until the lock is released. This means that multiple instances of the same class can use the same lock.

On the other hand, an object level lock is a lock on a specific object and is acquired by using the "synchronized" keyword on a non-static method or block. This lock prevents any other thread from accessing any synchronized non- static method or block of the same object until the lock is released. This means that multiple objects of the same class can have their own locks.

In summary, a class level lock is acquired on the entire class and is shared by all objects of that class, while an object level lock is acquired on a specific object and is not shared by other objects of the same class.