commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (BEANUTILS-440) MethodUtils.CACHE_METHODS is not accessed in a thread-safe way
Date Fri, 21 Jun 2013 15:18:22 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-440?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13690373#comment-13690373
] 

Sebb commented on BEANUTILS-440:
--------------------------------

The fundamental problem here is that the field is static and mutable.

In general, mutable static fields are thread-hostile; you can ensure that they are published
correctly, but that does not make the class thread-safe.

In this particular case, if one thread wants to use caching and another does not, what happens?
I think the only way to solve it would be to single-thread the access to the class.
Or use ThreadLocal, but then there is extra garbage to collect.

Best never to design classes that have mutable static fields.
                
> MethodUtils.CACHE_METHODS is not accessed in a thread-safe way
> --------------------------------------------------------------
>
>                 Key: BEANUTILS-440
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-440
>             Project: Commons BeanUtils
>          Issue Type: Bug
>            Reporter: Sebb
>         Attachments: BEANUTILS-440.patch
>
>
> MethodUtils.CACHE_METHODS is not accessed in a thread-safe way.
> The field is a mutable static field, but is not volatile (nor Atomic) and only write
accesses are synchronised.
> If one thread writes the field, other reader threads may not see the updates immediately
(or ever). 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message