Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-511

Initialization of available locales in LocaleUtils can be deferred

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4
    • 2.5
    • lang.*
    • None

    Description

      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.)

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              oheger Oliver Heger
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: