| | |
| | | import jakarta.annotation.PreDestroy; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.mdm.machinefile.filewatch.DirectorLockService; |
| | | import org.springblade.mdm.machinefile.filewatch.FileWatcherService; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @AllArgsConstructor |
| | | @Component |
| | | public class ShutdownHook { |
| | | private final DirectorLockService directorLockService; |
| | | private final FileWatcherService fileWatcherService; |
| | | @PreDestroy |
| | | public void onExit() { |
| | | System.out.println("执行退出前清理操作..."); |
| | | // 1. 关闭文件监控 |
| | | // 2. 释放资源 |
| | | // 3. 保存状态 |
| | | // 4. 通知其他服务 |
| | | directorLockService.releaseLock(); |
| | | |
| | | fileWatcherService.shutdown(); |
| | | } |
| | | } |