|
|
@ -27,7 +27,8 @@ public class JobScheduleHelper {
|
|
|
|
|
|
|
|
|
|
|
|
private Thread scheduleThread;
|
|
|
|
private Thread scheduleThread;
|
|
|
|
private Thread ringThread;
|
|
|
|
private Thread ringThread;
|
|
|
|
private volatile boolean toStop = false;
|
|
|
|
private volatile boolean scheduleThreadToStop = false;
|
|
|
|
|
|
|
|
private volatile boolean ringThreadToStop = false;
|
|
|
|
private volatile static Map<Integer, List<Integer>> ringData = new ConcurrentHashMap<>();
|
|
|
|
private volatile static Map<Integer, List<Integer>> ringData = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
public void start(){
|
|
|
|
public void start(){
|
|
|
@ -40,13 +41,13 @@ public class JobScheduleHelper {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
TimeUnit.MILLISECONDS.sleep(5000 - System.currentTimeMillis()%1000 );
|
|
|
|
TimeUnit.MILLISECONDS.sleep(5000 - System.currentTimeMillis()%1000 );
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
if (!toStop) {
|
|
|
|
if (!scheduleThreadToStop) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.info(">>>>>>>>> init xxl-job admin scheduler success.");
|
|
|
|
logger.info(">>>>>>>>> init xxl-job admin scheduler success.");
|
|
|
|
|
|
|
|
|
|
|
|
while (!toStop) {
|
|
|
|
while (!scheduleThreadToStop) {
|
|
|
|
|
|
|
|
|
|
|
|
// 扫描任务
|
|
|
|
// 扫描任务
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
@ -127,7 +128,7 @@ public class JobScheduleHelper {
|
|
|
|
|
|
|
|
|
|
|
|
conn.commit();
|
|
|
|
conn.commit();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (!toStop) {
|
|
|
|
if (!scheduleThreadToStop) {
|
|
|
|
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#scheduleThread error:{}", e);
|
|
|
|
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#scheduleThread error:{}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -152,7 +153,7 @@ public class JobScheduleHelper {
|
|
|
|
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis()%1000);
|
|
|
|
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis()%1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
if (!toStop) {
|
|
|
|
if (!scheduleThreadToStop) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -175,13 +176,13 @@ public class JobScheduleHelper {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis()%1000 );
|
|
|
|
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis()%1000 );
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
if (!toStop) {
|
|
|
|
if (!ringThreadToStop) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int lastSecond = -1;
|
|
|
|
int lastSecond = -1;
|
|
|
|
while (!toStop) {
|
|
|
|
while (!ringThreadToStop) {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// second data
|
|
|
|
// second data
|
|
|
@ -216,7 +217,7 @@ public class JobScheduleHelper {
|
|
|
|
ringItemData.clear();
|
|
|
|
ringItemData.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (!toStop) {
|
|
|
|
if (!ringThreadToStop) {
|
|
|
|
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#ringThread error:{}", e);
|
|
|
|
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#ringThread error:{}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -225,7 +226,7 @@ public class JobScheduleHelper {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis()%1000);
|
|
|
|
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis()%1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
if (!toStop) {
|
|
|
|
if (!ringThreadToStop) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -239,8 +240,15 @@ public class JobScheduleHelper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void toStop(){
|
|
|
|
public void toStop(){
|
|
|
|
toStop = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1、stop schedule
|
|
|
|
|
|
|
|
scheduleThreadToStop = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
TimeUnit.SECONDS.sleep(1); // wait
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scheduleThread.getState() != Thread.State.TERMINATED){
|
|
|
|
// interrupt and wait
|
|
|
|
// interrupt and wait
|
|
|
|
scheduleThread.interrupt();
|
|
|
|
scheduleThread.interrupt();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -248,7 +256,35 @@ public class JobScheduleHelper {
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if has ring data
|
|
|
|
|
|
|
|
boolean hasRingData = false;
|
|
|
|
|
|
|
|
if (!ringData.isEmpty()) {
|
|
|
|
|
|
|
|
for (int second : ringData.keySet()) {
|
|
|
|
|
|
|
|
List<Integer> tmpData = ringData.get(second);
|
|
|
|
|
|
|
|
if (tmpData!=null && tmpData.size()>0) {
|
|
|
|
|
|
|
|
hasRingData = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasRingData) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
TimeUnit.SECONDS.sleep(8);
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// stop ring (wait job-in-memory stop)
|
|
|
|
|
|
|
|
ringThreadToStop = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
TimeUnit.SECONDS.sleep(1);
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ringThread.getState() != Thread.State.TERMINATED){
|
|
|
|
// interrupt and wait
|
|
|
|
// interrupt and wait
|
|
|
|
ringThread.interrupt();
|
|
|
|
ringThread.interrupt();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -258,4 +294,7 @@ public class JobScheduleHelper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(">>>>>>>>>>> xxl-job, JobScheduleHelper stop");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|