forked from brianway/java-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun3_formatError.java
More file actions
49 lines (43 loc) · 1.93 KB
/
Copy pathRun3_formatError.java
File metadata and controls
49 lines (43 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.brianway.learning.java.multithread.supplement.example3;
/**
* Created by Brian on 2016/4/17.
*/
import java.text.SimpleDateFormat;
/**
* P293
* SimpleDateFormat类非线程安全
* 有时正常运行,有时报异常
*/
public class Run3_formatError {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String[] dateStringArray = new String[] {
"2000-01-01", "2000-01-02", "2000-01-03", "2000-01-04", "2000-01-05",
"2000-01-06", "2000-01-07", "2000-01-08", "2000-01-09", "2000-01-10"
};
Thread0[] threads = new Thread0[10];
for (int i = 0; i < 10; i++) {
threads[i] = new Thread0(sdf, dateStringArray[i]);
}
for (int i = 0; i < 10; i++) {
threads[i].start();
}
}
}
/*
ThreadName = Thread-6报错了 日期字符串:2000-01-07 转换成的日期为1999-12-02
ThreadName = Thread-4报错了 日期字符串:2000-01-05 转换成的日期为2000-01-09
ThreadName = Thread-1报错了 日期字符串:2000-01-02 转换成的日期为1999-12-02
ThreadName = Thread-0报错了 日期字符串:2000-01-01 转换成的日期为2000-01-05
ThreadName = Thread-5报错了 日期字符串:2000-01-06 转换成的日期为1999-12-03
Exception in thread "Thread-3" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:601)
at java.lang.Long.parseLong(Long.java:631)
at java.text.DigitList.getLong(DigitList.java:195)
at java.text.DecimalFormat.parse(DecimalFormat.java:2051)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1869)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1514)
at java.text.DateFormat.parse(DateFormat.java:364)
at com.brianway.learning.java.multithread.supplement.example3.Thread0.run(Thread0.java:22)
*/