How Synchronization works in Java?

后端 未结 8 586
广开言路
广开言路 2020-12-08 21:46

I have a doubt regarding Java Synchronization . I want to know if I have three Synchronized methods in my class and a thread acquires lock in one synchronized method other t

8条回答
  •  一向
    一向 (楼主)
    2020-12-08 22:21

    I'm not sure what it is you find confusing, but acquiring a lock blocks other threads from acquiring it while you hold it, and all non-static synchronized methods of a class synchronize on the same object, so the answer to your question is 'yes', assuming I have understood you correctly. I don't know what else 'synchronized' could mean, or what use it would be with any other meaning.

提交回复
热议问题