Details
-
Improvement
-
Status: Open
-
Critical
-
Resolution: Unresolved
-
1.2.7
-
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.