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

    • Type: Improvement
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.2.7
    • Fix Version/s: Pending Review
    • Component/s: None
    • Labels:
      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

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

              Dates

              • Created:
                Updated: