Calling two synchronous methods on the same line causes a dead end?

If the class has two synchronized methods:

public class A { public synchronized int do1() {...} public synchronized void do2(int i) {...} } 

Calling these two methods on the same line causes a dead end?

 A a = new A(); a.do2(a.do1()); 
+8
java synchronization
source share
1 answer

Note that in your example, the two methods do not call at the same time .

There is a clear strict order between them - do2() cannot be called until do1() is executed!

Also note that the code is equivalent

 A a = new A(); int temp = a.do1(); a.do2(temp); 
+9
source share

All Articles