Skip to content

Commit

Permalink
框架底层守护线程异常处理逻辑优化,避免极端情况下因Error导致调度终止、丢失问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxueli committed Nov 30, 2024
1 parent 7dc8c7a commit 267c1dd
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
9 changes: 5 additions & 4 deletions doc/XXL-JOB官方文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -2401,10 +2401,11 @@ public void execute() {
### 7.36 版本 v2.5.0 Release Notes[规划中]
- 1、【优化】部分系统日志优化,提升可读性;
- 2、[规划中]升级springboot3.x,解决2.x老版本漏洞类问题。注意,springboot3.x依赖jdk17。
- 3、[规划中]安全功能增强,通讯加密参数改用加密数据避免AccessToken明文, 降低token泄漏风险。
- 4、[规划中]登陆态Token声称逻辑优化,混淆登陆时间属性,降低token泄漏风险。
- 1、【优化】框架底层守护线程异常处理逻辑优化,避免极端情况下因Error导致调度终止、丢失问题。
- 2、【优化】部分系统日志优化,提升可读性;
- 3、[规划中]升级springboot3.x,解决2.x老版本漏洞类问题。注意,springboot3.x依赖jdk17。
- 4、[规划中]安全功能增强,通讯加密参数改用加密数据避免AccessToken明文, 降低token泄漏风险。
- 5、[规划中]登陆态Token声称逻辑优化,混淆登陆时间属性,降低token泄漏风险。
### TODO LIST
- 1、调度隔离:调度中心针对不同执行器,各自维护不同的调度和远程触发组件。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void run() {
// wait for JobTriggerPoolHelper-init
try {
TimeUnit.MILLISECONDS.sleep(50);
} catch (InterruptedException e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -92,15 +92,15 @@ public void run() {
}

}
} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(">>>>>>>>>>> xxl-job, job fail monitor thread error:{}", e);
}
}

try {
TimeUnit.SECONDS.sleep(60);
} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -127,7 +127,7 @@ public void toStop(){
monitorThread.interrupt();
try {
monitorThread.join();
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public void run() {
}
}

} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(">>>>>>>>>>> xxl-job, job fail monitor thread error:{}", e);
}
}

try {
TimeUnit.SECONDS.sleep(10);
} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -102,7 +102,7 @@ public void toStop(){
monitorThread.interrupt();
try {
monitorThread.join();
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void run() {
}
}

} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(">>>>>>>>>>> xxl-job, job log report thread error:{}", e);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public void run() {

try {
TimeUnit.MINUTES.sleep(1);
} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -144,7 +144,7 @@ public void toStop(){
logrThread.interrupt();
try {
logrThread.join();
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ public void run() {
XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().update(group);
}
}
} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);
}
}
try {
TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
} catch (InterruptedException e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(">>>>>>>>>>> xxl-job, job registry monitor thread error:{}", e);
}
Expand All @@ -138,7 +138,7 @@ public void toStop(){
registryMonitorThread.interrupt();
try {
registryMonitorThread.join();
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -44,7 +43,7 @@ public void run() {

try {
TimeUnit.MILLISECONDS.sleep(5000 - System.currentTimeMillis()%1000 );
} catch (InterruptedException e) {
} catch (Throwable e) {
if (!scheduleThreadToStop) {
logger.error(e.getMessage(), e);
}
Expand Down Expand Up @@ -150,7 +149,7 @@ public void run() {
// tx stop


} catch (Exception e) {
} catch (Throwable e) {
if (!scheduleThreadToStop) {
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#scheduleThread error:{}", e);
}
Expand All @@ -160,21 +159,21 @@ public void run() {
if (conn != null) {
try {
conn.commit();
} catch (SQLException e) {
} catch (Throwable e) {
if (!scheduleThreadToStop) {
logger.error(e.getMessage(), e);
}
}
try {
conn.setAutoCommit(connAutoCommit);
} catch (SQLException e) {
} catch (Throwable e) {
if (!scheduleThreadToStop) {
logger.error(e.getMessage(), e);
}
}
try {
conn.close();
} catch (SQLException e) {
} catch (Throwable e) {
if (!scheduleThreadToStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -185,7 +184,7 @@ public void run() {
if (null != preparedStatement) {
try {
preparedStatement.close();
} catch (SQLException e) {
} catch (Throwable e) {
if (!scheduleThreadToStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -200,7 +199,7 @@ public void run() {
try {
// pre-read period: success > scan each second; fail > skip this period;
TimeUnit.MILLISECONDS.sleep((preReadSuc?1000:PRE_READ_MS) - System.currentTimeMillis()%1000);
} catch (InterruptedException e) {
} catch (Throwable e) {
if (!scheduleThreadToStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -227,7 +226,7 @@ public void run() {
// align second
try {
TimeUnit.MILLISECONDS.sleep(1000 - System.currentTimeMillis() % 1000);
} catch (InterruptedException e) {
} catch (Throwable e) {
if (!ringThreadToStop) {
logger.error(e.getMessage(), e);
}
Expand Down Expand Up @@ -255,7 +254,7 @@ public void run() {
// clear
ringItemData.clear();
}
} catch (Exception e) {
} catch (Throwable e) {
if (!ringThreadToStop) {
logger.error(">>>>>>>>>>> xxl-job, JobScheduleHelper#ringThread error:{}", e);
}
Expand All @@ -269,7 +268,7 @@ public void run() {
ringThread.start();
}

private void refreshNextValidTime(XxlJobInfo jobInfo, Date fromTime) throws Exception {
private void refreshNextValidTime(XxlJobInfo jobInfo, Date fromTime) {
try {
Date nextValidTime = generateNextValidTime(jobInfo, fromTime);
if (nextValidTime != null) {
Expand All @@ -283,7 +282,7 @@ private void refreshNextValidTime(XxlJobInfo jobInfo, Date fromTime) throws Exce
logger.error(">>>>>>>>>>> xxl-job, refreshNextValidTime fail for job: jobId={}, scheduleType={}, scheduleConf={}",
jobInfo.getId(), jobInfo.getScheduleType(), jobInfo.getScheduleConf());
}
} catch (Exception e) {
} catch (Throwable e) {
// generateNextValidTime error, stop job
jobInfo.setTriggerStatus(0);
jobInfo.setTriggerLastTime(0);
Expand Down Expand Up @@ -312,15 +311,15 @@ public void toStop(){
scheduleThreadToStop = true;
try {
TimeUnit.SECONDS.sleep(1); // wait
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
if (scheduleThread.getState() != Thread.State.TERMINATED){
// interrupt and wait
scheduleThread.interrupt();
try {
scheduleThread.join();
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand All @@ -339,7 +338,7 @@ public void toStop(){
if (hasRingData) {
try {
TimeUnit.SECONDS.sleep(8);
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand All @@ -348,15 +347,15 @@ public void toStop(){
ringThreadToStop = true;
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
if (ringThread.getState() != Thread.State.TERMINATED){
// interrupt and wait
ringThread.interrupt();
try {
ringThread.join();
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void run() {
try {
// do trigger
XxlJobTrigger.trigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam, addressList);
} catch (Exception e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
} finally {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ public void initChannel(SocketChannel channel) throws Exception {

} catch (InterruptedException e) {
logger.info(">>>>>>>>>>> xxl-job remoting server stop.");
} catch (Exception e) {
} catch (Throwable e) {
logger.error(">>>>>>>>>>> xxl-job remoting server error.", e);
} finally {
// stop
try {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
} catch (Exception e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ private Object process(HttpMethod httpMethod, String uri, String requestData, St
default:
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, uri-mapping(" + uri + ") not found.");
}
} catch (Exception e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
return new ReturnT<String>(ReturnT.FAIL_CODE, "request error:" + ThrowableUtil.toString(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public void run() {
} else {
logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
}
} catch (Exception e) {
} catch (Throwable e) {
logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
}

}
} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -69,7 +69,7 @@ public void run() {
if (!toStop) {
TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
}
} catch (InterruptedException e) {
} catch (Throwable e) {
if (!toStop) {
logger.warn(">>>>>>>>>>> xxl-job, executor registry thread interrupted, error msg:{}", e.getMessage());
}
Expand All @@ -89,15 +89,15 @@ public void run() {
} else {
logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
}
} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
}

}

}
} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -119,7 +119,7 @@ public void toStop() {
registryThread.interrupt();
try {
registryThread.join();
} catch (InterruptedException e) {
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void run() {
}
}

} catch (Exception e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(e.getMessage(), e);
}
Expand All @@ -90,7 +90,7 @@ public void run() {

try {
TimeUnit.DAYS.sleep(1);
} catch (InterruptedException e) {
} catch (Throwable e) {
if (!toStop) {
logger.error(e.getMessage(), e);
}
Expand Down
Loading

0 comments on commit 267c1dd

Please sign in to comment.