How Synchronization works in Java?

后端 未结 8 584
广开言路
广开言路 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:24

    well, there is only one lock per object. and all synchronized methods are locked by this lock. So , whichever thread acquires lock at a time, it is authorized to go through all synchronized methods. But the threads which waits for the lock can't enter into synchronize methods until they get the lock.

    So at a time only only thread rules and others have to wait to enter any synchronized method, doesn't matter the ruling thread is executing that method or not.

提交回复
热议问题