1
1
package com .jeiao .thread ;
2
2
3
+ import com .jeiao .ThreadMain ;
3
4
import com .jeiao .bean .OrderBean ;
4
5
import com .jeiao .common .MemoryCache ;
5
6
import com .jeiao .queue .OrderBeanQueue ;
8
9
9
10
10
11
import java .util .concurrent .CountDownLatch ;
12
+ import java .util .concurrent .Executors ;
11
13
12
14
13
15
/**
@@ -30,31 +32,44 @@ public OrderBeanThread(String threadName, CountDownLatch countDownLatch) {
30
32
}
31
33
32
34
public void run () {
35
+ try {
36
+ while (!OrderBeanQueue .isEmpty ()) {
37
+ OrderBean orderBean = OrderBeanQueue .getOrder ();
33
38
34
- while (!OrderBeanQueue .isEmpty ()) {
35
- OrderBean orderBean = OrderBeanQueue .getOrder ();
39
+ if (orderBean == null ) {
40
+ continue ;
41
+ }
36
42
37
- if (orderBean == null ) {
38
- continue ;
39
- }
40
43
41
- try {
42
- Thread .sleep (1000 );
43
- } catch (InterruptedException e ) {
44
- e .printStackTrace ();
45
- }
44
+ //测试
45
+ //int i = 1 / 0;
46
+
47
+ try {
48
+ Thread .sleep (1000 );
49
+ } catch (InterruptedException e ) {
50
+ ThreadMain .threadStatus ++;
51
+ e .printStackTrace ();
52
+ throw new Exception (e );
53
+ }
46
54
47
- logger .info (threadName );
48
- logger .info (countDownLatch .getCount ());
49
55
50
- String orderId = orderBean .getOrderId ();
51
56
52
- //do something
57
+ logger .info (threadName );
58
+ logger .info (countDownLatch .getCount ());
53
59
54
- MemoryCache . orderBeanMap . put ( orderId , orderBean );
60
+ String orderId = orderBean . getOrderId ( );
55
61
62
+ //do something
63
+
64
+ MemoryCache .orderBeanMap .put (orderId , orderBean );
65
+ }
66
+ } catch (Exception e ) {
67
+ ThreadMain .threadStatus ++;
68
+ throw new RuntimeException ("线程处理异常,线程退出" );
69
+
70
+ }finally {
71
+ countDownLatch .countDown ();
72
+ logger .info (countDownLatch .getCount ());
56
73
}
57
- countDownLatch .countDown ();
58
- logger .info (countDownLatch .getCount ());
59
74
}
60
75
}
0 commit comments