Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shichaoyuan opened this issue Jan 31, 2024 · 1 comment · Fixed by #3353
Closed

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

shichaoyuan opened this issue Jan 31, 2024 · 1 comment · Fixed by #3353

Comments

@shichaoyuan
Copy link
Contributor

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

@robberphex
Copy link
Collaborator

robberphex commented Feb 28, 2024

是可以这样修改的,欢迎提交这个PR。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants