[jboss-jira] [JBoss JIRA] Closed: (JBAS-5564) Probable logical problem in NonReentrantLock

Adrian Brock (JIRA) jira-events at lists.jboss.org
Fri May 30 08:45:48 EDT 2008


     [ http://jira.jboss.com/jira/browse/JBAS-5564?page=all ]

Adrian Brock closed JBAS-5564.
------------------------------

    Resolution: Rejected

"It is a single write, multiple read lock"

You can't do that. EJB instances cannot be invoked upon in multiple threads concurrently,
it breaks their contract. See the EJB spec.

Concurrent invocations on the same entity requires instance-per-transaction configurations
as per the FAQ.

"The problem is probably in EntityReentranceInterceptor but the conversation about the problem is completely in this ticket, so I re-open the ticket."

Conversations/questions belong in the forums not bug reports.
Please don't open this again.

> Probable logical problem in NonReentrantLock
> --------------------------------------------
>
>                 Key: JBAS-5564
>                 URL: http://jira.jboss.com/jira/browse/JBAS-5564
>             Project: JBoss Application Server
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: EJB2
>    Affects Versions: JBossAS-5.0.0.Beta4, JBossAS-4.2.2.GA
>         Environment: None, source code analysis
>            Reporter: Domagoj Cosic
>
> Introduction: My direct problem is distantly related to JBAS-4177. The difference is, I use an own implementation of a BeanLock, which is so far correct an not an issue in this ticket, nor is the my original problem that the NonReentrantLock causes. However, my original problem led me to NonReentrantLock and I analyzed its source code in some depth. I have a suspicion that there is a serious bug in it.
> The problem I want to point at is in the line 143:
> Up to the trunk revision there stands:
> 	if(lockHolder != curThread && (miTx == null || miTx.equals(holdingTx)))
> There is some contradiction to the description:
> "It will throw a ReentranceException if the same thread tries to acquire twice
> or the same transaction tries to acquire twice"
> For a non re-entrant bean it means, in pseudo code:
> if (sameThread or sameTransaction) {
>  throw new ReentrantException();
> } else {
>  waitForOtherThreadOrTransaction;
>  on timeout return false;
>  return true;
> }
> This description does not apply to an re-entrant bean, but for re-entrant bean it basically means (in pseudo code):
> if (sameThread or sameTransaction) {
>  return true;
> } else {
>  waitForOtherThreadOrTransaction;
>  on timeout return false;
>  return true;
> }
> I backtracked the code to the previous change, which was revision 16662 dated 27.08.2003
> There it stands:
>             if (lockHolder == Thread.currentThread()) throw new ReentranceException();
>             if (miTx != null && miTx.equals(holdingTx)) throw new ReentranceException();
> Although this code was for the non re-eantrant case, for the re-entrant case the code should return true for those cases, where ReentrantException was thrown.
> Let us transform this code step by step:
> Step 1:
>             if (lockHolder == Thread.currentThread()) return true;
>             if (miTx != null && miTx.equals(holdingTx)) return true;
> Step 2:
>             if (lockHolder == Thread.currentThread() || miTx != null && miTx.equals(holdingTx)) {
>             	return true;
>             } else {
>             	wait;
>             	return true;
>             }
> Step 3 (negating):
>             if (lockHolder != Thread.currentThread() && (miTx == null || !miTx.equals(holdingTx))) {
>             	wait;
>             	return true;
>             } else {
>             	return true;
>             }
> You see the difference? Current code lacks "!" before miTx.equals(holdingTx). It seems wrong to me and it causes a problem for me, so it would be nice if someone else takes a look at this.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list