Config druid datasource as below:
`
@Bean(name = chanceDataSourceMaster, initMethod = "init", destroyMethod = "close")
@Primary
@Qualifier
public DruidDataSource dataSourceMaster() throws SQLException {
return getDruidDataSource(driverClassName, dbMaterUrl, dbMaterUsername, dbMaterPassword);
}
@Bean(name = "chanceDataSourceSlave", initMethod = "init", destroyMethod = "close")
@Qualifier
public DruidDataSource dataSourceSlave() throws SQLException {
return getDruidDataSource(driverClassName, dbSlaveUrl, dbSlaveUsername, dbSlavePassword);
}
private DruidDataSource getDruidDataSource(String driverClassName, String jdbcUrl, String username, String password) throws SQLException {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driverClassName);
dataSource.setUrl(jdbcUrl);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setMaxActive(this.maxActive);
dataSource.setInitialSize(this.initialSize);
dataSource.setMinIdle(this.minIdle);
dataSource.setTimeBetweenEvictionRunsMillis(10000);
dataSource.setMinEvictableIdleTimeMillis(30000);
dataSource.setValidationQuery("SELECT 'x'");
dataSource.setTestWhileIdle(true);
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setRemoveAbandoned(true);
dataSource.setRemoveAbandonedTimeout(1800);
dataSource.setLogAbandoned(true);
dataSource.setFilters("stat");
dataSource.setConnectionProperties("druid.stat.slowSqlMillis=100");
//设置sql连接字符编码 utf8mb4
Set<String> set = new HashSet<>();
set.add("set names utf8mb4;");
dataSource.setConnectionInitSqls(set);
return dataSource;
}`
Memory leak countered, please check the jprofiler snapshot: https://github.com/ArayChou/static/blob/master/druid_dump.jpg
1条答案
按热度按时间kcrjzv8t1#
[root@xxxx]# uname -a
Linux xxxx 3.10.0-862.3.2.el7.x86_64 #1 SMP Mon May 21 23:36:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@xxxx]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
[root@xxxx]# ps -ef | grep java | grep -v grep
root 202 187 1 Jul24 ? 00:15:59 java -Xms1228m -Xmx1228m -Xmn460m -Dlog4j.file.path=/xxxx -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/xxxx/java.hprof -verbose:gc -Xloggc:/xxxx/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Djava.awt.headless=true -XX:+DisableExplicitGC -javaagent:/xxxx/pinpoint-bootstrap-1.6.0.jar -Dpinpoint.agentId=test_1532415433461 -Dpinpoint.applicationName=/xxxx -jar /xxxx.jar