[jboss-jira] [JBoss JIRA] Commented: (EJBTHREE-1501) Operations on cacheMap are not thread safe
Galder Zamarreno (JIRA)
jira-events at lists.jboss.org
Tue Sep 23 12:50:20 EDT 2008
[ https://jira.jboss.org/jira/browse/EJBTHREE-1501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12430840#action_12430840 ]
Galder Zamarreno commented on EJBTHREE-1501:
--------------------------------------------
I'll leave this open in case anyone from the EJB3 team
can think of a situation where this might be an issue.
Otherwise, I'll close it in the next couple of days.
> 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: AS 4.2.3.GA, 1.0.0-Beta3
> 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
More information about the jboss-jira
mailing list