Commit be998f94 authored by hongguangwu's avatar hongguangwu

1.7.21-临时文件延迟删除

parent 5327de79
......@@ -205,6 +205,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
// 此方法是:删除临时文件
public void cleanSpireTempFiles() {
try {
// 暂停1分钟
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
}
String tempDirPath = System.getProperty("java.io.tmpdir");
File tempDir = new File(tempDirPath);
......@@ -216,15 +222,19 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
if (spireTempFiles != null && spireTempFiles.length > 0) {
int count = 0;
long totalSize = 0;
long oneMinuteAgo = System.currentTimeMillis() - 60000;
long fileSize;
for (File file : spireTempFiles) {
if (file.isFile() && file.canWrite()) {
long fileSize = file.length();
if (file.isFile() && file.canWrite() && file.lastModified() < oneMinuteAgo) {
fileSize = file.length();
if (file.delete()) {
count++;
totalSize += fileSize;
}
}
}
}
log.info("清理 Spire.XLS 临时文件完成:删除 {} 个文件,释放 {} MB 空间",
count, totalSize / 1024 / 1024);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment