Browse Source

update document

xuxueli 6 years ago
parent
commit
248a1bbe69

+ 11 - 5
xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobScheduleHelper.java View File

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