|
@@ -98,14 +98,24 @@ public class ScheduleUtil {
|
|
|
public static Map<String, Object> cancel(String serviceId) {
|
|
|
System.out.println("关闭定时任务线程 taskId " + serviceId);
|
|
|
ScheduledFuture<?> scheduledFuture = scheduledFutureMap.remove(serviceId);
|
|
|
- if (scheduledFuture != null && !scheduledFuture.isCancelled()) {
|
|
|
- scheduledFuture.cancel(false);
|
|
|
- try {
|
|
|
- DATA_BASE.update(Config.getCenterConnectionStr(), "update serviceinfo set runState = 0 where serviceid =?", serviceId);
|
|
|
- } catch (Exception e) {
|
|
|
- return UniReturnUtil.fail(e);
|
|
|
+ while (scheduledFuture != null && !scheduledFuture.isCancelled()) {
|
|
|
+ boolean cancel = scheduledFuture.cancel(false);
|
|
|
+ if (cancel) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException ignored) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return UniReturnUtil.success(true);
|
|
|
+ scheduleTaskMaps.remove(serviceId);
|
|
|
+ try {
|
|
|
+ DATA_BASE.update(Config.getCenterConnectionStr(), "update servicestate set runstate = 0 where serviceid =? and containercode = ?", serviceId,Config.getContainerCode());
|
|
|
+ return UniReturnUtil.success(true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return UniReturnUtil.fail(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|