[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/06/2009 at 03:05PM PST, ID: 24879589 | Points: 500
[x]
Attachment Details

another java deadlock question

Asked by wrynn in Java Editors & IDEs, J2EE, New to Java Programming

the following code results in deadlock because the bone would be locked by the synchronized statement that calls .chew(this) correct? and the solution is to instead of using synchronized(this) use synchronized(otherLockObject) ?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
class Bone {
     
     synchronized(this) { 
          Dog.getInstance().chew(this);
     }
} 
class Dog {
      private set Set = new HashSet();
      synchronized(this){
          public void chew(Bone bone) {
              set.add(bone)
          }
       }
}
[+][-]11/06/09 03:40 PM, ID: 25764061

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 06:22 PM, ID: 25764715

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625