I am having an object of a class having some state.
This object has two methods (method1()
and method2()
), both are changing the state of obj
.
method1()
is synchronized but method2()
is not synchronized.
Now two threads, thread1 and threads2 approach object
->threads1 calls method1()
which is synchronized
-> thread2 calls method2()
which is not synchronized.
What I found with my test results is the method2()
was executing correctly even though method1()
holding a lock. But I thought that if a lock is acquired on the entire object by putting the synchronised keyword on method, how many another method can be executed. It should wait.
Your opinion is highly appreciated.