Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

线程池变更:executeTimeOut 变更极端情况下会出现异常 #405

Closed
lizhifuabc opened this issue Jul 27, 2022 · 1 comment · Fixed by #414
Closed

线程池变更:executeTimeOut 变更极端情况下会出现异常 #405

lizhifuabc opened this issue Jul 27, 2022 · 1 comment · Fixed by #414
Labels
in: hippo4j-config type: bug Something isn't working
Milestone

Comments

@lizhifuabc
Copy link

lizhifuabc commented Jul 27, 2022

@OverRide
protected void beforeExecute(Thread t, Runnable r) {
// 案例1 :executeTimeOut :变更前 1,变更后 0
// 案例2 :executeTimeOut :变更前 0,变更后 1
if (executeTimeOut == null || executeTimeOut <= 0) {
return;
}
// 案例1 :executeTimeOut :变更前 1
// 案例2 :executeTimeOut :变更前 0,此时startTime空
this.startTime.set(SystemClock.now());
}
@OverRide
protected void afterExecute(Runnable r, Throwable t) {
// 案例1 :executeTimeOut :变更后 0,此时直接返回了,不会执行 this.startTime.remove();
// 案例2 :executeTimeOut :变更后 1, long startTime = this.startTime.get(); NPE
if (executeTimeOut == null || executeTimeOut <= 0) {
return;
}
try {
long startTime = this.startTime.get();
long endTime = SystemClock.now();
long executeTime;
boolean executeTimeAlarm = (executeTime = (endTime - startTime)) > executeTimeOut;
if (executeTimeAlarm && ApplicationContextHolder.getInstance() != null) {
ThreadPoolNotifyAlarmHandler notifyAlarmHandler = ApplicationContextHolder.getBean(ThreadPoolNotifyAlarmHandler.class);
if (notifyAlarmHandler != null) {
notifyAlarmHandler.asyncSendExecuteTimeOutAlarm(threadPoolId, executeTime, executeTimeOut, this);
}
}
} finally {
this.startTime.remove();
}
}

@magestacks
Copy link
Member

@lizhifuabc 感谢反馈,如果有兴趣的话,可以提交个 pr。如无反馈,最近我会修复这个问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: hippo4j-config type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants