最近项目一直会出现时间转换报错,一直不知道是什么问题,
java.lang.NumberFormatException: multiple points
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1110)
at java.lang.Double.parseDouble(Double.java:540)
at java.text.DigitList.getDouble(DigitList.java:168)
at java.text.DecimalFormat.parse(DecimalFormat.java:1321)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1793)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1455)
报错的地方是项目用SimpleDateFormat写了个DateUtil工具类,用来时间转换的,代码如下:
-
public final class DateUtil {
-
-
private static SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd");
-
-
-
public static Date parseDateTime(String dateTimeStr) {
-
try {
-
return dateFormat.parse(dateTimeStr);
-
} catch (ParseException e) {
-
// TODO Auto-generated catch block
-
e.printStackTrace();
-
}
-
return null;
-
}
-
-
}
return dateFormat.parse(dateTimeStr);
偶偶会报java.lang.NumberFormatException: multiple points或者报java.lang.NumberFormatException: For input string: ".31023102EE22"
今天实在是忍受了,百度了下,原来是SimpleDateFormat是非线程安全的,在多线程情况下会有问题,在每个线程下得各自new SimpleDateFormat()就可以了