Types of Lock in java object

What are the types of lock in java(like Object level, Class level lock). and how these are used in the application.

Thanks & Regards,
Pankaj Patro

Vaibhav Chauhan

Ranch Hand

Posts: 115

posted 10 years ago

Object level lock: this is the lock that any thread aquires over nonstatic synchronized method. Any thread can invoke the synchronized method for different object other than the object that has invoked the synchronized method.

Class level lock: this is the lock that any thread aquires over static synchronized method. No thread can invoke the synchronized method for any object until the first thread which is having the lock releases it.

We need not to worry about locks during coding, it is decided by compiler depending upon keyword static.

I know only two locks, if there is any other locks please respond with answer.