Skip to content


8316454: JFR break locale settings
Browse files Browse the repository at this point in the history
Reviewed-by: mgronlun
  • Loading branch information
egahlin committed Dec 7, 2023
1 parent c42535f commit de95259
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ private static enum TimespanUnit {

private static final NumberFormat NUMBER_FORMAT = NumberFormat.getNumberInstance();
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss");
private static final Duration MICRO_SECOND = Duration.ofNanos(1_000);
private static final Duration SECOND = Duration.ofSeconds(1);
Expand All @@ -69,6 +68,12 @@ private static enum TimespanUnit {
private static final int DISPLAY_NANO_DIGIT = 3;
private static final int BASE = 10;

// -XX:FlightRecorderOptions:repository=<path> triggers an upcall
// which will load this class. If NumberFormat.getNumberInstance()
// is called during startup, locale settings will not take effect.
// Workaround is to create an instance lazily. See numberFormatInstance().
private static NumberFormat NUMBER_FORMAT;

public static String formatTimespan(Duration dValue, String separation) {
if (dValue == null) {
return "0";
Expand Down Expand Up @@ -110,8 +115,15 @@ private static void appendPadded(StringBuilder text, int number, boolean separat

private static NumberFormat numberFormatInstance() {
if (NUMBER_FORMAT == null) {
NUMBER_FORMAT = NumberFormat.getNumberInstance();

public static String formatNumber(Number n) {
return NUMBER_FORMAT.format(n);
return numberFormatInstance().format(n);

public static String formatDuration(Duration d) {
Expand Down

1 comment on commit de95259

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.