[jboss-jira] [JBoss JIRA] Commented: (EJBTHREE-1501) Operations on cacheMap are not thread safe
Brian Stansberry (JIRA)
jira-events at lists.jboss.org
Tue Sep 23 11:55:21 EDT 2008
[ https://jira.jboss.org/jira/browse/EJBTHREE-1501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12430826#action_12430826 ]
Brian Stansberry commented on EJBTHREE-1501:
--------------------------------------------
That's going to hold the map lock through a potentially long-running call to container.destroy(ctx) which calls any @PreDestroy.
Before incurring that cost, what's the scenario where this is a problem, and can that scenario be solved another way, e.g. with a finer-grained lock, e.g. on the context rather than the cacheMap?
> 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