java - Can a thread acquire a lock on a instance of a class,when other thread is executing a static synchronized method of this class? -


suppose have

class {     void m1() {         synchronized (this) {         }         blah blah blah         synchronized (this) {         }     } } 

my doubt while executing blah blah blah, executing thread object o release lock, @ time if other thread object o acquires lock, there deadlock. how can should try use synchronized block instead of synchronized method?

suppose thread t1 executing static synchronized method acquires class level lock, can other thread acquire lock of instance of class execute other synchronized methods?

while executing "blah blah blah", executing thread doesn't own locks. possible thread acquire lock on object, won't cause deadlock. first thread block until other thread releases lock.

a deadlock occurs when thread owns lock 1, needs lock 2 while thread b owns lock 2 needs lock 1. isn't occurring in situation.

a class level lock different lock lock on object instance. so, class level lock won't interfere thread executing other synchronized methods on object.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -