mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 15:37:28 +00:00
fix: CacheManager registerPeriodicCleanup 添加防重入和 Vertx 就绪检查
审查发现 static 块中注册定时任务存在时序风险:如果 CacheServiceImpl 在 Vertx 初始化前被加载,定时任务将注册失败且无法恢复。添加 cleanupRegistered 标志防止 重复注册,Vertx 未就绪时跳过并等待下次调用。
This commit is contained in:
@@ -232,9 +232,17 @@ public class CacheManager {
|
|||||||
* 注册定时清理过期缓存任务(每小时执行一次)
|
* 注册定时清理过期缓存任务(每小时执行一次)
|
||||||
* 应在应用启动后调用
|
* 应在应用启动后调用
|
||||||
*/
|
*/
|
||||||
|
private static volatile boolean cleanupRegistered = false;
|
||||||
|
|
||||||
public static void registerPeriodicCleanup() {
|
public static void registerPeriodicCleanup() {
|
||||||
|
if (cleanupRegistered) return;
|
||||||
try {
|
try {
|
||||||
io.vertx.core.Vertx vertx = cn.qaiu.vx.core.util.VertxHolder.getVertxInstance();
|
io.vertx.core.Vertx vertx = cn.qaiu.vx.core.util.VertxHolder.getVertxInstance();
|
||||||
|
if (vertx == null) {
|
||||||
|
LOGGER.warn("Vertx 未就绪,缓存定时清理任务延迟注册");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cleanupRegistered = true;
|
||||||
vertx.setPeriodic(3600_000, 3600_000, id -> {
|
vertx.setPeriodic(3600_000, 3600_000, id -> {
|
||||||
try {
|
try {
|
||||||
new CacheManager().cleanupExpiredCache();
|
new CacheManager().cleanupExpiredCache();
|
||||||
|
|||||||
Reference in New Issue
Block a user