Operations on cacheMap are not thread safe
------------------------------------------
Key: EJBTHREE-1501
URL:
https://jira.jboss.org/jira/browse/EJBTHREE-1501
Project: EJB 3.0
Issue Type: Sub-task
Affects Versions: 1.0.0-Beta3, AS 4.2.3.GA
Reporter: Galder Zamarreno
Assignee: Galder Zamarreno
Finally, code like this is not thread safe:
synchronized (cacheMap)
{
ctx = (StatefulBeanContext) cacheMap.get(key);
}
if(ctx == null)
throw new NoSuchEJBException("Could not find Stateful bean: " + key);
if (!ctx.isRemoved())
container.destroy(ctx);
++removeCount;
if (ctx.getCanRemoveFromCache())
{
synchronized (cacheMap)
{
cacheMap.remove(key);
}
}
This is essentiall a removeIfPresent type of operation on cacheMap and hence
get() and remove() operation, as they depend on each other, should be in a
single synchronized statement. Example:
synchronized (cacheMap)
{
ctx = (StatefulBeanContext) cacheMap.get(key);
if(ctx == null)
throw new NoSuchEJBException("Could not find Stateful bean: " +
key);
if (!ctx.isRemoved())
container.destroy(ctx);
++removeCount;
if (ctx.getCanRemoveFromCache())
{
cacheMap.remove(key);
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira