Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-3192

Why lazy instantiation of the MessageResourcesFactory in Struts 1.2.7?

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • 1.2.7
    • Pending Review
    • None
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jcblancomartinez Juan Carlos Blanco Martinez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: