1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

fix thread-unsafe about SimpleDateFormat

This commit is contained in:
pyh_uestc
2019-05-24 17:11:55 +08:00
parent c3e5e4cafa
commit 6fbb0fb1f4
5 changed files with 31 additions and 11 deletions

View File

@@ -41,7 +41,12 @@ public class NacosConfigEndpoint {
private final NacosRefreshHistory refreshHistory;
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>(){
@Override
protected DateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
};
public NacosConfigEndpoint(NacosConfigProperties properties,
NacosRefreshHistory refreshHistory) {
@@ -60,7 +65,7 @@ public class NacosConfigEndpoint {
for (NacosPropertySource ps : all) {
Map<String, Object> source = new HashMap<>(16);
source.put("dataId", ps.getDataId());
source.put("lastSynced", dateFormat.format(ps.getTimestamp()));
source.put("lastSynced", dateFormat.get().format(ps.getTimestamp()));
sources.add(source);
}
result.put("Sources", sources);