Commit 952116fc by shentao

2018/4/27 超时控制

parent 66bad2e5
......@@ -378,8 +378,7 @@ public class ES4RedisTask {
log.info("{}项目本次获取消息数:{}", project.getProjectName(), num);
} catch (Exception e) {
log.error("{} {}", e.getMessage(), e.getStackTrace());
e.printStackTrace();
log.error("项目本次获取获取出错或超时{}{}", e.getMessage(), e.getStackTrace());
return false;
}
return true;
......
......@@ -64,6 +64,18 @@ public class ES4RedisThread extends Thread {
// 通知执行run方法
t.start();
}
// 超时控制器
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// 超时则线程中止
if (t.isAlive()) {
t.interrupt();
log.warn("{}项目超时线程状态:{}", project.getProjectName(),t.isInterrupted());
}
}
}, 49 * 1000L);
}
@SuppressWarnings("static-access")
......@@ -74,15 +86,15 @@ public class ES4RedisThread extends Thread {
Thread.sleep(10L);
// 超时控制器
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// 超时则线程中止
Thread.currentThread().interrupted();
log.warn("{}项目超时", project.getProjectName());
}
}, 49 * 1000L);
// Timer timer = new Timer();
// timer.schedule(new TimerTask() {
// @Override
// public void run() {
// // 超时则线程中止
// Thread.currentThread().interrupted();
// log.warn("{}项目超时", project.getProjectName());
// }
// }, 49 * 1000L);
// 程序运行
log.info("Running {}", threadName);
......@@ -92,12 +104,13 @@ public class ES4RedisThread extends Thread {
if (!flag) {
// 程序执行出现异常则线程中止
timer.cancel();
// timer.cancel();
Thread.currentThread().interrupted();
log.error("{}项目出现异常", project.getProjectName());
} else
// 程序正常执行完毕,关闭超时控制器
timer.cancel();
log.error("{}项目出现异常,线程状态:{}", project.getProjectName(),Thread.currentThread().isInterrupted());
}
// else
// // 程序正常执行完毕,关闭超时控制器
// timer.cancel();
} catch (JsonParseException e) {
e.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment