Regarding the Lock associated with an object

Hi all,

suppose we are having an object with 2 synchronized methods and this object is being shared by two threads. Suppose, if the first thread access one synchronized method and the second thread access the other synchronized method, then my doubt is whether any one of these threads needs to wait to get the lock or they can execute at the same time?

[366 byte] By [hareesh_84a] at [2007-11-26 20:02:12]
# 1

when using a synchronized method,

public synchronized void foo()

{

...

}

you are really doing

public void foo()

{

synchronized(this)

{

....

}

}

If two threads are synchronizing on the same instance, at the same time, then one will wait. So in you case, yes on thread will wait.

dmbdmba at 2007-7-9 23:01:13 > top of Java-index,Java Essentials,Java Programming...