|
@@ -48,7 +48,8 @@ public class JobScheduleHelper {
|
48
|
48
|
|
49
|
49
|
while (!toStop) {
|
50
|
50
|
|
51
|
|
- // 匹配任务
|
|
51
|
+ // 扫描任务
|
|
52
|
+ long start = System.currentTimeMillis();
|
52
|
53
|
Connection conn = null;
|
53
|
54
|
PreparedStatement preparedStatement = null;
|
54
|
55
|
try {
|
|
@@ -143,10 +144,11 @@ public class JobScheduleHelper {
|
143
|
144
|
}
|
144
|
145
|
}
|
145
|
146
|
}
|
|
147
|
+ long cost = System.currentTimeMillis()-start;
|
146
|
148
|
|
147
|
|
- // 随机休眠1s内
|
|
149
|
+ // next second, align second
|
148
|
150
|
try {
|
149
|
|
- TimeUnit.MILLISECONDS.sleep(500+new Random().nextInt(500));
|
|
151
|
+ TimeUnit.MILLISECONDS.sleep(cost<1000?(1000-cost):100);
|
150
|
152
|
} catch (InterruptedException e) {
|
151
|
153
|
if (!toStop) {
|
152
|
154
|
logger.error(e.getMessage(), e);
|
|
@@ -167,6 +169,7 @@ public class JobScheduleHelper {
|
167
|
169
|
@Override
|
168
|
170
|
public void run() {
|
169
|
171
|
|
|
172
|
+ // align second
|
170
|
173
|
try {
|
171
|
174
|
TimeUnit.MILLISECONDS.sleep(System.currentTimeMillis()%1000 );
|
172
|
175
|
} catch (InterruptedException e) {
|
|
@@ -178,6 +181,7 @@ public class JobScheduleHelper {
|
178
|
181
|
int lastSecond = -1;
|
179
|
182
|
while (!toStop) {
|
180
|
183
|
|
|
184
|
+ long start = System.currentTimeMillis();
|
181
|
185
|
try {
|
182
|
186
|
// second data
|
183
|
187
|
List<Integer> ringItemData = new ArrayList<>();
|
|
@@ -199,7 +203,7 @@ public class JobScheduleHelper {
|
199
|
203
|
}
|
200
|
204
|
lastSecond = nowSecond;
|
201
|
205
|
|
202
|
|
-
|
|
206
|
+ // ring trigger
|
203
|
207
|
logger.debug(">>>>>>>>>>> xxl-job, time-ring beat : " + nowSecond + " = " + Arrays.asList(ringItemData) );
|
204
|
208
|
if (ringItemData!=null && ringItemData.size()>0) {
|
205
|
209
|
// do trigger
|
|
@@ -215,9 +219,11 @@ public class JobScheduleHelper {
|
215
|
219
|
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#ringThread error:{}", e);
|
216
|
220
|
}
|
217
|
221
|
}
|
|
222
|
+ long cost = System.currentTimeMillis() - start;
|
218
|
223
|
|
|
224
|
+ // next second, align second
|
219
|
225
|
try {
|
220
|
|
- TimeUnit.SECONDS.sleep(1);
|
|
226
|
+ TimeUnit.MILLISECONDS.sleep(1000-cost);
|
221
|
227
|
} catch (InterruptedException e) {
|
222
|
228
|
if (!toStop) {
|
223
|
229
|
logger.error(e.getMessage(), e);
|