If a class has two synchronized methods:
public class A {
public synchronized int do1() {...}
public synchronized void do2(int i) {...}
}
Will invoking these two methods in one line cause a deadlock?
A a = new A();
a.do2(a.do1());
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note that in your example, the two methods are not invoked concurrently.
There is a clear strict order between them –
do2()cannot be invoked untildo1()is done!Also note, the code is equivalent to