1.40
This commit is contained in:
parent
718bbf9ddd
commit
17b8f69c19
@ -133,6 +133,32 @@ public class ThreadPoolConfig {
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 审计事件处理线程池 - 使用虚拟线程(Java 21+)
|
||||
*
|
||||
* ⚠️ 为什么使用虚拟线程?
|
||||
* 1. 审计事件处理是**I/O密集型**任务(写日志、写数据库)
|
||||
* 2. 虚拟线程在I/O阻塞时不占用OS线程,资源消耗极低
|
||||
* 3. 审计事件量可能很大,虚拟线程支持高并发处理
|
||||
* 4. 独立线程池避免与业务线程池竞争资源
|
||||
*
|
||||
* 💡 场景:
|
||||
* - 异步记录用户操作审计日志
|
||||
* - 写入审计数据库
|
||||
* - 发送审计事件到消息队列
|
||||
*
|
||||
* 🎯 解决问题:
|
||||
* - 修复 "More than one TaskExecutor bean found" 警告
|
||||
* - 确保审计事件处理不受其他业务线程池影响
|
||||
*/
|
||||
@Bean("auditTaskExecutor")
|
||||
public SimpleAsyncTaskExecutor auditTaskExecutor() {
|
||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("audit-virtual-");
|
||||
executor.setVirtualThreads(true);
|
||||
executor.setConcurrencyLimit(-1); // 无限制,支持大量并发审计事件
|
||||
return executor;
|
||||
}
|
||||
|
||||
// ========== 注意 ==========
|
||||
// sshOutputExecutor 已迁移到 Framework 层
|
||||
// 见: framework.ssh.websocket.SSHWebSocketConfig
|
||||
|
||||
@ -42,7 +42,11 @@ public class AuditAspect {
|
||||
} catch (Exception e) {
|
||||
// 记录异常信息
|
||||
metadata.setDetail(metadata.getDetail() + " [Error: " + e.getMessage() + "]");
|
||||
|
||||
// 发布审计事件
|
||||
eventPublisher.publishEvent(new AuditEvent(this, metadata));
|
||||
|
||||
// 重新抛出异常
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class AuditEventListener {
|
||||
|
||||
@Async
|
||||
@Async("auditTaskExecutor")
|
||||
@EventListener
|
||||
public void handleAuditEvent(AuditEvent event) {
|
||||
// 这里可以将审计信息保存到数据库或发送到日志系统
|
||||
|
||||
Loading…
Reference in New Issue
Block a user