[
https://issues.apache.org/struts/browse/STR-3192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46898#action_46898
]
Paul Benedict commented on STR-3192:
------------------------------------
This class follows the "abstract toolkit" pattern in which it instantiates a
factory, and then the factory instantiates the actual objects. Perhaps the
pattern isn't totally necessary, but I don't know what can be done about this.
MessageResourcesFactory is probably used many places. Refactoring would entail
not referencing MessageResourcesFactory once the factory is obtained. Got any
ideas on that one?
> 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
>
>
> Since there is the Double-checked locking issue so we have to use
> synchronization to guarantee the concurrent access to the following method
> (org.apache.struts.util.MessageResources class) :
> LAZY INSTANTIATION
> public synchronized static MessageResources getMessageResources(String
> config) {
> if (defaultFactory == null) {
> defaultFactory = MessageResourcesFactory.createFactory();
> }
> return defaultFactory.createResources(config);
> }
> Why not to use:
> EAGER INSTANTIATION
> static {
> // Construct a new instance of the specified factory class
> try {
> if (clazz == null)
> clazz = RequestUtils.applicationClass(factoryClass);
> MessageResourcesFactory defaultFactory =
> (MessageResourcesFactory) clazz.newInstance();
> } catch (Throwable t) {
> LOG.error("MessageResourcesFactory.createFactory", t);
> }
> }
> 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.