1
1
package com .vip .saturn .job .basic ;
2
2
3
3
import com .vip .saturn .job .SaturnJobReturn ;
4
+ import com .vip .saturn .job .utils .LogUtils ;
4
5
import org .slf4j .Logger ;
5
6
import org .slf4j .LoggerFactory ;
6
7
@@ -72,12 +73,11 @@ public SaturnJobReturn call() throws Exception {
72
73
@ Override
73
74
public void uncaughtException (Thread t , Throwable e ) {
74
75
if (e instanceof IllegalMonitorStateException || e instanceof ThreadDeath ) {
75
- log .warn (String .format (SaturnConstant .LOG_FORMAT_FOR_STRING , callable .getJobName (),
76
- "business thread pool maybe crashed" ), e );
76
+ LogUtils .warn (log , callable .getJobName (), "business thread pool maybe crashed" , e );
77
77
if (callFuture != null ) {
78
78
callFuture .cancel (false );
79
79
}
80
- log .warn (SaturnConstant . LOG_FORMAT , callable .getJobName (),
80
+ LogUtils .warn (log , callable .getJobName (),
81
81
"close the old business thread pool, and re-create new one" );
82
82
callable .getSaturnJob ().getJobScheduler ().reCreateExecutorService ();
83
83
}
@@ -89,8 +89,8 @@ public void uncaughtException(Thread t, Throwable e) {
89
89
return ret ;
90
90
} finally {
91
91
done ();
92
- log .debug ("job:[{}] item:[{}] finish execution, which takes {}ms" , callable . getJobName () ,
93
- callable .getItem (), callable .getExecutionTime ());
92
+ LogUtils .debug (log , callable . getJobName (), "job:[{}] item:[{}] finish execution, which takes {}ms" ,
93
+ callable .getJobName (), callable . getItem (), callable .getExecutionTime ());
94
94
}
95
95
}
96
96
@@ -110,17 +110,15 @@ private void done() {
110
110
callable .onTimeout ();
111
111
}
112
112
} catch (Throwable t ) {
113
- log .error (String .format (SaturnConstant .LOG_FORMAT_FOR_STRING , callable .getJobName (), t .getMessage ()),
114
- t );
113
+ LogUtils .error (log , callable .getJobName (), t .toString (), t );
115
114
}
116
115
117
116
try {
118
117
if (callable .isForceStop ()) {
119
118
callable .postForceStop ();
120
119
}
121
120
} catch (Throwable t ) {
122
- log .error (String .format (SaturnConstant .LOG_FORMAT_FOR_STRING , callable .getJobName (), t .getMessage ()),
123
- t );
121
+ LogUtils .error (log , callable .getJobName (), t .toString (), t );
124
122
}
125
123
126
124
callable .checkAndSetSaturnJobReturn ();
@@ -133,8 +131,7 @@ private void done() {
133
131
doneFinallyCallback .call ();
134
132
}
135
133
} catch (Exception e ) {
136
- log .error (String .format (SaturnConstant .LOG_FORMAT_FOR_STRING , callable .getJobName (), e .getMessage ()),
137
- e );
134
+ LogUtils .error (log , callable .getJobName (), e .toString (), e );
138
135
}
139
136
}
140
137
}
@@ -146,31 +143,31 @@ public static void killRunningBusinessThread(ShardingItemFutureTask shardingItem
146
143
try {
147
144
// interrupt thread one time, wait business thread to break, wait 2000ms at most
148
145
if (!isBusinessBreak (shardingItemFutureTask , shardingItemCallable )) {
149
- log .info ("try to interrupt business thread" );
146
+ LogUtils .info (log , shardingItemCallable . getJobName (), "try to interrupt business thread" );
150
147
businessThread .interrupt ();
151
148
for (int i = 0 ; i < 20 ; i ++) {
152
149
if (isBusinessBreak (shardingItemFutureTask , shardingItemCallable )) {
153
- log .info ("interrupt business thread done" );
150
+ LogUtils .info (log , shardingItemCallable . getJobName (), "interrupt business thread done" );
154
151
return ;
155
152
}
156
153
Thread .sleep (100L );
157
154
}
158
155
}
159
156
// stop thread
160
157
while (!isBusinessBreak (shardingItemFutureTask , shardingItemCallable )) {
161
- log .info ("try to force stop business thread" );
158
+ LogUtils .info (log , shardingItemCallable . getJobName (), "try to force stop business thread" );
162
159
businessThread .stop ();
163
160
if (isBusinessBreak (shardingItemFutureTask , shardingItemCallable )) {
164
- log .info ("force stop business thread done" );
161
+ LogUtils .info (log , shardingItemCallable . getJobName (), "force stop business thread done" );
165
162
return ;
166
163
}
167
164
Thread .sleep (50L );
168
165
}
169
- log .info ("kill business thread done" );
166
+ LogUtils .info (log , shardingItemCallable . getJobName (), "kill business thread done" );
170
167
} catch (InterruptedException e ) {// NOSONAR
171
168
}
172
169
} else {
173
- log .warn ("business thread is null while killing it" );
170
+ LogUtils .warn (log , shardingItemCallable . getJobName (), "business thread is null while killing it" );
174
171
}
175
172
}
176
173
0 commit comments