You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Juan Carlos Blanco Martinez (JIRA)" <ji...@apache.org> on 2009/10/06 10:32:50 UTC

[jira] Issue Comment Edited: (STR-3192) Why lazy instantiation of the MessageResourcesFactory in Struts 1.2.7?

    [ https://issues.apache.org/struts/browse/STR-3192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46893#action_46893 ] 

Juan Carlos Blanco Martinez edited comment on STR-3192 at 10/6/09 1:32 AM:
---------------------------------------------------------------------------

Because, since the messages are needed from the very first request, it makes sense to me to eagerly load them rather than using the lazy instantiation, thus the performance (I know it doesn't make a huge difference but still) won't be affected by the synchronization.

      was (Author: jcblancomartinez):
    Because, since the messages are needed from the very first request, it makes sense for me to eagerly load them rather than using the lazy instantiation, thus the performance (I know it doesn't make a huge difference but still) won't be affected by the synchronization.
  
> Why lazy instantiation of the MessageResourcesFactory in Struts 1.2.7?
> ----------------------------------------------------------------------
>
>                 Key: STR-3192
>                 URL: https://issues.apache.org/struts/browse/STR-3192
>             Project: Struts 1
>          Issue Type: Improvement
>    Affects Versions: 1.2.7
>            Reporter: Juan Carlos Blanco Martinez
>            Priority: Critical
>             Fix For: Pending Review
>
>
> Double-checked locking issue exists and one of the options to solve this is to use synchronization. In the class org.apache.struts.util.MessageResources, we use LAZY INSTANTIATION to instantiate MessageResourcesFactory:
> public synchronized static MessageResources getMessageResources(String config) {
>     if (defaultFactory == null) {
>         defaultFactory = MessageResourcesFactory.createFactory();
>     }
>     return defaultFactory.createResources(config);
> }
> Why not to use:
> EAGER INSTANTIATION
> private static MessageResourcesFactory defaultFactory = MessageResourcesFactory.createFactory();
> And then:
> public static MessageResources getMessageResources(String config) {
>     return defaultFactory.createResources(config);
> }
> It would allow concurrent access to the method getMessageResources which at least in my case it may be called quite a few times.

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