Details
-
Enhancement
-
Resolution: Fixed
-
P4
-
None
Description
Running this will have the side effect of initializing all Charsets in the JDK (and in any application provided extensions):
public class CharsetAvailable {
public static void main(String ... args) {
java.nio.charset.Charset.availableCharsets();
}
}
When analyzing the cost of this, it's apparent that the majority of time is spent initializing the charset encoding and decoding mapping data. Since it's unlikely more than a few charsets will actually be used in any given application, doing this initialization lazily - by means of holder classes - seems profitable.
Using a holder class idiom also mean that all DoubleByte charsets - which currently use lazy initialization using DCL - can optimize better.
public class CharsetAvailable {
public static void main(String ... args) {
java.nio.charset.Charset.availableCharsets();
}
}
When analyzing the cost of this, it's apparent that the majority of time is spent initializing the charset encoding and decoding mapping data. Since it's unlikely more than a few charsets will actually be used in any given application, doing this initialization lazily - by means of holder classes - seems profitable.
Using a holder class idiom also mean that all DoubleByte charsets - which currently use lazy initialization using DCL - can optimize better.