[ 
https://issues.apache.org/struts/browse/WW-2834?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Kirk Rasmussen updated WW-2834:
-------------------------------

    Description: 
Here is a snippet from com.opensymphony.xwork2.util.LocalizedTextUtil that 
illustrates one (could be more) problem. This could be easily fixed by using 
the JDK 1.5 ConcurrentHashMap collection instead. I guess technically this is 
an XWork problem.


    private static final Map messageFormats = new HashMap();

    private static MessageFormat buildMessageFormat(String pattern, Locale 
locale) {
        MessageFormatKey key = new MessageFormatKey(pattern, locale);
        MessageFormat format = (MessageFormat) messageFormats.get(key);
        if (format == null) {
            format = new MessageFormat(pattern);
            format.setLocale(locale);
            format.applyPattern(pattern);
            messageFormats.put(key, format);
        }

        return format;
    }

Also the MessageFormat class itself is not thread safe and must be syncronized.


  was:
Here is a snippet from com.opensymphony.xwork2.util.LocalizedTextUtil that 
illustrates one (could be more) problem. This could be easily fixed by using 
the JDK 1.5 ConcurrentHashMap collection instead. I guess technically this is 
an XWork problem.


    private static final Map messageFormats = new HashMap();

    private static MessageFormat buildMessageFormat(String pattern, Locale 
locale) {
        MessageFormatKey key = new MessageFormatKey(pattern, locale);
        MessageFormat format = (MessageFormat) messageFormats.get(key);
        if (format == null) {
            format = new MessageFormat(pattern);
            format.setLocale(locale);
            format.applyPattern(pattern);
            messageFormats.put(key, format);
        }

        return format;
    }



> LocalizedTextUtil messageFormats cache is NOT thread safe
> ---------------------------------------------------------
>
>                 Key: WW-2834
>                 URL: https://issues.apache.org/struts/browse/WW-2834
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.0.11.2
>            Reporter: Kirk Rasmussen
>            Priority: Critical
>
> Here is a snippet from com.opensymphony.xwork2.util.LocalizedTextUtil that 
> illustrates one (could be more) problem. This could be easily fixed by using 
> the JDK 1.5 ConcurrentHashMap collection instead. I guess technically this is 
> an XWork problem.
>     private static final Map messageFormats = new HashMap();
>     private static MessageFormat buildMessageFormat(String pattern, Locale 
> locale) {
>         MessageFormatKey key = new MessageFormatKey(pattern, locale);
>         MessageFormat format = (MessageFormat) messageFormats.get(key);
>         if (format == null) {
>             format = new MessageFormat(pattern);
>             format.setLocale(locale);
>             format.applyPattern(pattern);
>             messageFormats.put(key, format);
>         }
>         return format;
>     }
> Also the MessageFormat class itself is not thread safe and must be 
> syncronized.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to