Skip to content

替换ThreadLocal<SimpleDateFormat>以适配Java21虚拟线程 #3321

@shichaoyuan

Description

@shichaoyuan

Issue Description

private static final ThreadLocal<FastDateFormat> dateFmt = new ThreadLocal<FastDateFormat>() {
@Override
protected FastDateFormat initialValue() {
return new FastDateFormat();
}
};

private final ThreadLocal<SimpleDateFormat> dateFormatThreadLocal = new ThreadLocal<SimpleDateFormat>() {
@Override
public SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
};

private final ThreadLocal<SimpleDateFormat> dateFormatThreadLocal = new ThreadLocal<SimpleDateFormat>() {
@Override
public SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd");
}
};

代码中的ThreadLocal对Java21中的 virtual thread 并不友好。

而且从Java8开始已经推荐使用 java.time.format.DateTimeFormatter,这是一个 "This class is immutable and thread-safe." 的实现。

Describe your initial design

是否可以将这些地方换成 java.time.format.DateTimeFormatter

如果可以的话,我愿意提PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions