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:16:01 +08:00
parent 6fbb0fb1f4
commit 2cb7327a78
2 changed files with 10 additions and 6 deletions

View File

@ -15,7 +15,6 @@
*/
package org.springframework.cloud.alicloud.sms.base;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -159,9 +158,9 @@ public class DefaultAlicomMessagePuller {
if (!polling) {
popMsg = queue.popMessage();
if (debugLogOpen) {
ThreadLocal<DateFormat> format = new ThreadLocal<DateFormat>(){
ThreadLocal<SimpleDateFormat> format = new ThreadLocal<SimpleDateFormat>(){
@Override
protected DateFormat initialValue() {
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
};

View File

@ -78,8 +78,13 @@ public class TokenGetterForAlicom {
private TokenForAlicom getTokenFromRemote(String messageType)
throws ClientException, ParseException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
ThreadLocal<SimpleDateFormat> df = new ThreadLocal<SimpleDateFormat>(){
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
};
df.get().setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
QueryTokenForMnsQueueRequest request = new QueryTokenForMnsQueueRequest();
request.setAcceptFormat(FormatType.JSON);
request.setMessageType(messageType);
@ -94,7 +99,7 @@ public class TokenGetterForAlicom {
TokenForAlicom token = new TokenForAlicom();
String timeStr = dto.getExpireTime();
token.setMessageType(messageType);
token.setExpireTime(df.parse(timeStr).getTime());
token.setExpireTime(df.get().parse(timeStr).getTime());
token.setToken(dto.getSecurityToken());
token.setTempAccessKeyId(dto.getAccessKeyId());
token.setTempAccessKeySecret(dto.getAccessKeySecret());