|
@@ -49,17 +49,20 @@ public class JobScheduleHelper {
|
49
|
49
|
}
|
50
|
50
|
logger.info(">>>>>>>>> init xxl-job admin scheduler success.");
|
51
|
51
|
|
52
|
|
- Connection conn = null;
|
53
|
52
|
while (!scheduleThreadToStop) {
|
54
|
53
|
|
55
|
54
|
// Scan Job
|
56
|
55
|
long start = System.currentTimeMillis();
|
|
56
|
+
|
|
57
|
+ Connection conn = null;
|
|
58
|
+ Boolean connAutoCommit = null;
|
57
|
59
|
PreparedStatement preparedStatement = null;
|
|
60
|
+
|
58
|
61
|
boolean preReadSuc = true;
|
59
|
62
|
try {
|
60
|
|
- if (conn==null || conn.isClosed()) {
|
61
|
|
- conn = XxlJobAdminConfig.getAdminConfig().getDataSource().getConnection();
|
62
|
|
- }
|
|
63
|
+
|
|
64
|
+ conn = XxlJobAdminConfig.getAdminConfig().getDataSource().getConnection();
|
|
65
|
+ connAutoCommit = conn.getAutoCommit();
|
63
|
66
|
conn.setAutoCommit(false);
|
64
|
67
|
|
65
|
68
|
preparedStatement = conn.prepareStatement( "select * from xxl_job_lock where lock_name = 'schedule_lock' for update" );
|
|
@@ -169,11 +172,27 @@ public class JobScheduleHelper {
|
169
|
172
|
} finally {
|
170
|
173
|
|
171
|
174
|
// commit
|
172
|
|
- try {
|
173
|
|
- conn.commit();
|
174
|
|
- } catch (SQLException e) {
|
175
|
|
- if (!scheduleThreadToStop) {
|
176
|
|
- logger.error(e.getMessage(), e);
|
|
175
|
+ if (conn != null) {
|
|
176
|
+ try {
|
|
177
|
+ conn.commit();
|
|
178
|
+ } catch (SQLException e) {
|
|
179
|
+ if (!scheduleThreadToStop) {
|
|
180
|
+ logger.error(e.getMessage(), e);
|
|
181
|
+ }
|
|
182
|
+ }
|
|
183
|
+ try {
|
|
184
|
+ conn.setAutoCommit(connAutoCommit);
|
|
185
|
+ } catch (SQLException e) {
|
|
186
|
+ if (!scheduleThreadToStop) {
|
|
187
|
+ logger.error(e.getMessage(), e);
|
|
188
|
+ }
|
|
189
|
+ }
|
|
190
|
+ try {
|
|
191
|
+ conn.close();
|
|
192
|
+ } catch (SQLException e) {
|
|
193
|
+ if (!scheduleThreadToStop) {
|
|
194
|
+ logger.error(e.getMessage(), e);
|
|
195
|
+ }
|
177
|
196
|
}
|
178
|
197
|
}
|
179
|
198
|
|
|
@@ -204,12 +223,7 @@ public class JobScheduleHelper {
|
204
|
223
|
}
|
205
|
224
|
|
206
|
225
|
}
|
207
|
|
- if (conn != null) {
|
208
|
|
- try {
|
209
|
|
- conn.close();
|
210
|
|
- } catch (SQLException e) {
|
211
|
|
- }
|
212
|
|
- }
|
|
226
|
+
|
213
|
227
|
logger.info(">>>>>>>>>>> xxl-job, JobScheduleHelper#scheduleThread stop");
|
214
|
228
|
}
|
215
|
229
|
});
|