Alex Rivera | Logout

thread intrinsic lock

Asked 2010-07-29T10:18:17.413
12

When we talk about intrinsic lock we refer to the object for which we ask the lock or for the synchronized method?

The lock is on the object or on it's sync method?

I'm confused!

Edit
Report

1 Answer

1

The lock is part of the Object. Every Object has one and it may be locked in two ways:

  1. Using the synchronized modifier on an instance method of the Class to lock the associated object
  2. Using a synchronized(object) {} block

Similarly, you can lock the Class of an Object instead of the Object itself (bares mentioning separately to understand the synchronized modifier with a static method):

  1. Using the synchronized modifier on a static method of the Class to lock the Class
  2. Using a synchronized(clazz) {} block where clazz is the Class of the Object
answered 2010-07-29T10:25:27.617

Your Answer