Home > Back-end > Inquire of Java synchronized synchronization method of problem?
Inquire of Java synchronized synchronization method of problem?
Time:11-28
Class A { Public synchronized void doSomething1 { } Public synchronized void doSomething2 { } Public synchronized static void doSomething3 { } }
If a class contains both synchronized methods are static and non-static synchronization method, a new class of objects, open the ab two threads, if when performing non-static synchronization method, a thread b threads don't have access to the object other than static synchronization method, this is certain, If I want to ask is when performing non-static synchronization method, a thread b thread can perform static synchronous method? And if a thread synchronization method, static b thread can perform non-static synchronization method?
CodePudding user response:
Is static and non-static two locks, but perform static or non-static mutex,
CodePudding user response:
The static method must be in a static class, you can write like this