build(java): 升级Java版本至21并优化虚拟线程使用

- 将项目Java版本从17升级到21
- 替换ThreadUtil.execAsync为Thread.startVirtualThread以利用虚拟线程
This commit is contained in:
2025-10-31 15:03:29 +08:00
parent 3e3c10fa9d
commit dcf2528e5d
6 changed files with 8 additions and 14 deletions
@@ -45,14 +45,11 @@ public class CsWsClientManager {
CsWsServer wsServer = clientMap.get(sid); CsWsServer wsServer = clientMap.get(sid);
if (wsServer != null) { if (wsServer != null) {
try { try {
// log.info("关闭session, sid={}", sid); log.info("关闭session, sid={}", sid);
wsServer.getSession().close(); wsServer.getSession().close();
} catch (Exception e) { } catch (Exception e) {
log.error("Close session failed, sid={}", sid, e); log.error("Close session failed, sid={}", sid, e);
} }
// log.info("停止任务, sid={}", sid);
wsServer.stopTask(sid);
// log.info("移除客户端, sid={}", sid);
clientMap.remove(sid); clientMap.remove(sid);
} }
} }
@@ -62,7 +62,7 @@ public class OperationLogAspect {
try { try {
Object result = joinPoint.proceed(); Object result = joinPoint.proceed();
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval); SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval);
ThreadUtil.execAsync(() -> { Thread.startVirtualThread(() -> {
try { try {
systemOperationLogMapper.insert(record); systemOperationLogMapper.insert(record);
} catch (Exception e) { } catch (Exception e) {
@@ -73,7 +73,7 @@ public class OperationLogAspect {
} catch (Throwable exception) { } catch (Throwable exception) {
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval); SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval);
record.setExceptionDetail(ExceptionUtil.stacktraceToString(exception)); record.setExceptionDetail(ExceptionUtil.stacktraceToString(exception));
ThreadUtil.execAsync(() -> { Thread.startVirtualThread(() -> {
try { try {
systemOperationLogMapper.insert(record); systemOperationLogMapper.insert(record);
} catch (Exception e) { } catch (Exception e) {
@@ -62,7 +62,7 @@ public class SystemOperationLogAspect {
try { try {
Object result = joinPoint.proceed(); Object result = joinPoint.proceed();
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval); SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval);
ThreadUtil.execAsync(() -> { Thread.startVirtualThread(() -> {
try { try {
systemOperationLogMapper.insert(record); systemOperationLogMapper.insert(record);
} catch (Exception e) { } catch (Exception e) {
@@ -74,7 +74,7 @@ public class SystemOperationLogAspect {
} catch (Throwable exception) { } catch (Throwable exception) {
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval); SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval);
record.setExceptionDetail(ExceptionUtil.stacktraceToString(exception)); record.setExceptionDetail(ExceptionUtil.stacktraceToString(exception));
ThreadUtil.execAsync(() -> { Thread.startVirtualThread(() -> {
try { try {
systemOperationLogMapper.insert(record); systemOperationLogMapper.insert(record);
} catch (Exception e) { } catch (Exception e) {
@@ -50,7 +50,7 @@ public class TaskTestsController {
public ResponseEntity<?> testCreateAfterStop() { public ResponseEntity<?> testCreateAfterStop() {
TaskInstanceInfoTb instanceInfo = taskManage.createJob("cutejava", TaskChangeTypeEnum.AppContainerDeploy, "java", "daily", "cutejava", "功能测试", null); TaskInstanceInfoTb instanceInfo = taskManage.createJob("cutejava", TaskChangeTypeEnum.AppContainerDeploy, "java", "daily", "cutejava", "功能测试", null);
log.info("任务创建成功,实例为:{}", JSON.toJSONString(instanceInfo)); log.info("任务创建成功,实例为:{}", JSON.toJSONString(instanceInfo));
ThreadUtil.execAsync(() -> { Thread.startVirtualThread(() -> {
ThreadUtil.safeSleep(5000); ThreadUtil.safeSleep(5000);
taskManage.stopJob(instanceInfo.getId()); taskManage.stopJob(instanceInfo.getId());
}); });
+1 -1
View File
@@ -27,7 +27,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<java.version>17</java.version> <java.version>21</java.version>
<fastjson2.version>2.0.59</fastjson2.version> <fastjson2.version>2.0.59</fastjson2.version>
<druid.version>1.2.27</druid.version> <druid.version>1.2.27</druid.version>
<commons-pool2.version>2.11.1</commons-pool2.version> <commons-pool2.version>2.11.1</commons-pool2.version>
@@ -45,14 +45,11 @@ public class CsWsClientManager {
CsWsServer wsServer = clientMap.get(sid); CsWsServer wsServer = clientMap.get(sid);
if (wsServer != null) { if (wsServer != null) {
try { try {
// log.info("关闭session, sid={}", sid); log.info("关闭session, sid={}", sid);
wsServer.getSession().close(); wsServer.getSession().close();
} catch (Exception e) { } catch (Exception e) {
log.error("Close session failed, sid={}", sid, e); log.error("Close session failed, sid={}", sid, e);
} }
// log.info("停止任务, sid={}", sid);
wsServer.stopTask(sid);
// log.info("移除客户端, sid={}", sid);
clientMap.remove(sid); clientMap.remove(sid);
} }
} }