Commit 5baf3c68 by 田超

Merge branch 'feature/fix_mem_0201' into 'master'

feat:[none] 增加定时清理druid统计数据任务

See merge request rays/pcloud-common-parent!178
parents c0bc93e4 a6199f9a
...@@ -113,6 +113,9 @@ public class DataSourceConfig { ...@@ -113,6 +113,9 @@ public class DataSourceConfig {
ArrayList<String> arr = new ArrayList<>(); ArrayList<String> arr = new ArrayList<>();
arr.add("set names utf8mb4;"); arr.add("set names utf8mb4;");
datasource.setConnectionInitSqls(arr); datasource.setConnectionInitSqls(arr);
// 定时清理druid统计数据,避免占用内存过大
DruidStatsResetManager.resetScheduledWithFixedDelay();
} catch (SQLException e) { } catch (SQLException e) {
logger.error("druid configuration initialization filter", e); logger.error("druid configuration initialization filter", e);
} }
......
package com.pcloud.common.core.datasource;
import com.alibaba.druid.stat.DruidStatManagerFacade;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Druid统计数据重置
*/
class DruidStatsResetManager {
private static final Logger LOGGER = LoggerFactory.getLogger(DruidStatsResetManager.class);
private static final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1,
new BasicThreadFactory.Builder().namingPattern("druid-stats-reset-%d").build());
/**
* 定时重置
*/
static void resetScheduledWithFixedDelay() {
executor.scheduleWithFixedDelay(() -> {
DruidStatManagerFacade.getInstance().resetAll();
LOGGER.info("druid stats data reset all executed completed.");
}, 5, 5, TimeUnit.MINUTES);
}
}
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