-
1. Re: Entity bean deadlock
g_thimm Sep 25, 2009 1:23 PM (in response to bartatamas)Maybe you could use
A: getTitle() {
return name + getSync().getName(getB());
}
B: getTitle() {
return name + getSync().getName(getA());
}
Where Sync is a Singleton with
Sync:
syncronised getName(Bean b){
return b.getName();
}
This way the threads run without interference until on of them calls the getName() of Sync. At this point, one of them is prone to win the race, and the syncronisation within Sync avoids the deadlock.
The penalty for the indirect call to Sync should not be too bad if the three beans are in the same VM.
Didn't try it, though ;-)
Cheers ,
Georg -
2. Re: Entity bean deadlock
bartatamas Sep 28, 2009 2:02 AM (in response to bartatamas)I think it has the same problem.
thread1 is in A.getTitle so locks A.
thread2 is in B.getTitle so locks B.
thread1 gets B and calls Sync.getName(B), and waits for B there (in b.getName() because thread2 locks B)
thread2 gets A and waits for the Singleton to call getName(A), but thread1 will not return