I got this asked in an interview a few days ago. Can one thread access a synchronized non-static method and another thread access a synchronized static method at the same time? The methods belong to the same class. I know the answer is yes but I want to know how it is possible. Thanks.
The synchronization object for a non-static method is the object itself (this).
The synchronization object for a static method is the .class instance.
Both are different. Hence you can.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With