[jira] [Commented] (LANG-511) Initialization of available locales in LocaleUtils can be deferred

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (LANG-511) Initialization of available locales in LocaleUtils can be deferred

Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/LANG-511?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13283276#comment-13283276 ]

Maxence Dewil commented on LANG-511:
------------------------------------

commons-lang 3.x: the 'static initializer' way is ok. It would be probably better if the private static fields were final.
http://grepcode.com/file/repo1.maven.org/maven2/org.apache.commons/commons-lang3/3.1/org/apache/commons/lang3/LocaleUtils.java?av=f

commons-lang 2.x: the code is different from 3.x and there you have the DCL anti-pattern.
http://grepcode.com/file/repo1.maven.org/maven2/commons-lang/commons-lang/2.6/org/apache/commons/lang/LocaleUtils.java?av=f
               

> Initialization of available locales in LocaleUtils can be deferred
> ------------------------------------------------------------------
>
>                 Key: LANG-511
>                 URL: https://issues.apache.org/jira/browse/LANG-511
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 2.4
>            Reporter: Oliver Heger
>            Priority: Minor
>             Fix For: 2.5
>
>
> {{LocaleUtils}} has a static initializer block that initializes the list of locales available in the system. This is done by calling {{Locale.getAvailableLocales()}}.
> As I had to learn, {{getAvailableLocales()}} can be very expensive, depending on the environment in which it is called. Obviously, all jars in the class path are scanned to determine the supported locales. In our project we have a large number of jars on the class path, and the invocation of the method takes between 10 and 20 seconds. There is an entry in the Java Bug Database related to this issue:
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4908648
> {{LocaleUtils}} contains some methods that do not need the list of available locales (and in fact it is one of those methods we would like to use). So I wonder whether the initialization of the list of available locales could be done on demand. It would then have to be synchronized, but the advantage is that the expensive initialization is only performed if it is actually required.
> (LANG-488 is also related to this topic.)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira