-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.临时文件保留日期可通过配置文件修改 2.对fixed线程池状态监控 #2184
Open
wangshuai67
wants to merge
2
commits into
edp963:dev-0.3
Choose a base branch
from
wangshuai67:dev-0.3
base: dev-0.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,17 @@ | |
import edp.davinci.model.ShareDownloadRecord; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
@Slf4j | ||
@Component | ||
|
@@ -55,24 +59,37 @@ public class SystemSchedule { | |
|
||
@Autowired | ||
private ShareDownloadRecordMapper shareDownloadRecordMapper; | ||
@Value("${file.temp.remain.days:7}") | ||
private int fileTempRemainDays; | ||
@Value("${thread.pool.health.check.enable:true}") | ||
private boolean threadPoolHealthCheckEnable; | ||
|
||
private static final int THREAD_POOL_QUEUE_ALARM_SIZE=2000; | ||
private static final ExecutorService CLEAR_TEMPDIR_THREADPOOL = Executors.newFixedThreadPool(3); | ||
|
||
@Scheduled(cron = "0 0 1 * * *") | ||
public void clearTempDir() { | ||
|
||
//下载内容文件保留7天,记录保留1月 | ||
String downloadDir = fileUtils.fileBasePath + Consts.DIR_DOWNLOAD + DateUtils.getTheDayBeforeAWeekYYYYMMDD(); | ||
String tempDir = fileUtils.fileBasePath + Consts.DIR_TEMP + DateUtils.getTheDayBeforeNowDateYYYYMMDD(); | ||
String csvDir = fileUtils.fileBasePath + File.separator + FileTypeEnum.CSV.getType(); | ||
|
||
final String download = fileUtils.formatFilePath(downloadDir); | ||
final String temp = fileUtils.formatFilePath(tempDir); | ||
final String csv = fileUtils.formatFilePath(csvDir); | ||
|
||
CLEAR_TEMPDIR_THREADPOOL.execute(() -> FileUtils.deleteDir(new File(download))); | ||
CLEAR_TEMPDIR_THREADPOOL.execute(() -> FileUtils.deleteDir(new File(temp))); | ||
CLEAR_TEMPDIR_THREADPOOL.execute(() -> FileUtils.deleteDir(new File(csv))); | ||
checkThreadPoolExecutorStatus(); | ||
// 下载内容文件默认保留7天,记录保留1月,在月初和月末大数据量导出情况下部分文件删除IO异常失败,导致磁盘空间撑满 | ||
// 可自定义配置文件保留日期配置文件中file.temp.remain.days=n 运维可根据集团实际情况进行配置 | ||
String downloadDir=null ; | ||
String tempDir=null ; | ||
try { | ||
log.debug("下载内容文件默认保留[{}]天,可在配置文件通过file.temp.remain.days=n进行配置",fileTempRemainDays); | ||
downloadDir = fileUtils.fileBasePath + Consts.DIR_DOWNLOAD + DateUtils.getTheDayBeforeAWeekYYYYMMDD(fileTempRemainDays); | ||
tempDir = fileUtils.fileBasePath + Consts.DIR_TEMP + DateUtils.getTheDayBeforeNowDateYYYYMMDD(); | ||
String csvDir = fileUtils.fileBasePath + File.separator + FileTypeEnum.CSV.getType(); | ||
|
||
final String download = fileUtils.formatFilePath(downloadDir); | ||
final String temp = fileUtils.formatFilePath(tempDir); | ||
final String csv = fileUtils.formatFilePath(csvDir); | ||
log.info("downloadDir:{},tempDir:{},csv:{}",download,temp,csv); | ||
CLEAR_TEMPDIR_THREADPOOL.execute(() -> FileUtils.deleteDir(new File(download))); | ||
CLEAR_TEMPDIR_THREADPOOL.execute(() -> FileUtils.deleteDir(new File(temp))); | ||
CLEAR_TEMPDIR_THREADPOOL.execute(() -> FileUtils.deleteDir(new File(csv))); | ||
} catch (Exception e) { | ||
log.error("文件删除定时任务执行异常downloadDir:[{}],tempDir:[{}],请检查IO以及手动处理临时文件",downloadDir,tempDir); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议也一并输出下csv的目录,','和','需要统一 |
||
} | ||
} | ||
|
||
@Scheduled(cron = "0 0/2 * * * *") | ||
|
@@ -100,6 +117,32 @@ public void clearShareDownloadRecord() { | |
shareDownloadRecordMapper.deleteByCondition(); | ||
} | ||
|
||
/** | ||
* 线程池状态健康检查 | ||
* 可通过 thread.pool.health.check.enable=false 关闭监控检查 | ||
* @param | ||
*/ | ||
@Scheduled(cron = "${thread.pool.health.check.cron:0 0 1/1 * * *}") | ||
public void checkThreadPoolExecutorStatus(){ | ||
if(!threadPoolHealthCheckEnable){ | ||
return; | ||
} | ||
ThreadPoolExecutor tpe = ((ThreadPoolExecutor) CLEAR_TEMPDIR_THREADPOOL); | ||
int queueSize = tpe.getQueue().size(); | ||
int activeCount = tpe.getActiveCount(); | ||
long completedTaskCount = tpe.getCompletedTaskCount(); | ||
long taskCount = tpe.getTaskCount(); | ||
BlockingQueue<Runnable> queue = tpe.getQueue(); | ||
if(queue.size()>THREAD_POOL_QUEUE_ALARM_SIZE){ | ||
log.warn("当前排队线程数[{}],当前活动线程数[{}],执行完成线程数[{}],总线程数[{}]", queueSize, activeCount, completedTaskCount, taskCount); | ||
} | ||
if(queue.size()>THREAD_POOL_QUEUE_ALARM_SIZE*2){ | ||
log.error("线程执行效率异常,可能存在IO异常,当前排队线程数[{}],当前活动线程数[{}],执行完成线程数[{}],总线程数[{}]", queueSize, activeCount, completedTaskCount, taskCount); | ||
} | ||
else{ | ||
log.info("当前排队线程数[{}],当前活动线程数[{}],执行完成线程数[{}],总线程数[{}]", queueSize, activeCount, completedTaskCount, taskCount); | ||
} | ||
} | ||
private void deleteFile(File file){ | ||
if(file == null || !file.exists()){ | ||
return; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
临时文件保留日期如果是个没有层次的属性,建议使用file_temp_remain_days