Commit c611d8b9 by 李传峰

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

parent c0bc93e4
...@@ -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.");
}, 30, 30, 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