简体   繁体   English

如何减轻连接com.mysql.jdbc.JDBC4Connection@11d08960触发的连接泄漏,

[英]How do I mitigate Connection leak triggered for connection com.mysql.jdbc.JDBC4Connection@11d08960,

I have an mqtt client getting request subscribing from topics, and then I give it to threadpool of fixed size 50. Im using hikaricp 2.4.2 for DB Pooling MySQL database. 我有一个mqtt客户端从主题获取请求订阅,然后我将它提供给固定大小为50的线程池。我使用hikaricp 2.4.2 for DB Pooling MySQL数据库。

Im currently using 2.4.2 and this is my setup 我目前正在使用2.4.2,这是我的设置

    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(CLASS_FOR_NAME);
    config.setJdbcUrl(HOST);
    config.setUsername(USER);
    config.setPassword(PASS);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(30));
    config.setValidationTimeout(TimeUnit.MINUTES.toMillis(1));
    config.setMaximumPoolSize(10);
    config.setMinimumIdle(0);
    config.setMaxLifetime(TimeUnit.MINUTES.toMillis(2)); // 120 seconds 
    config.setIdleTimeout(TimeUnit.MINUTES.toMillis(1)); // minutes
    config.setConnectionTimeout(TimeUnit.MINUTES.toMillis(5)); 
    config.setConnectionTestQuery("/* ping */ SELECT 1");

Heres the full log message : 下面是完整的日志消息:

WARNLOG: WARNLOG:

811439 [Hikari housekeeper (pool HikariPool-0)] WARN com.zaxxer.hikari.pool.ProxyLeakTask - Connection leak detection triggered for connection com.mysql.jdbc.JDBC4Connection@11d0896, stack trace follows java.lang.Exception: Apparent connection leak detected at com.hcpdatabase.DataSource.getConnection(DataSource.java:69) at com.database.AccessDatabase.create_alert(AccessDatabase.java:3849) at com.runnable.StartTaskRunnable2.execute(StartTaskRunnable2.java:78) 811439 [Hikari管家(池HikariPool-0)]警告com.zaxxer.hikari.pool.ProxyLeakTask - 连接泄漏检测触发连接com.mysql.jdbc.JDBC4Connection@11d0896,堆栈跟踪跟踪java.lang.Exception:表观连接泄漏在com.database.AccessDatabase.create_alert(AccessDatabase.java:3849)com.runnable.StartTaskRunnable2.execute(StartTaskRunnable2.java:78)的com.hcpdatabase.DataSource.getConnection(DataSource.java:69)处检测到

Is this normal ? 这是正常的吗? do i have to catch this? 我必须抓住这个吗?

As I have reviewed my codes over and over again. 因为我一遍又一遍地审查了我的代码。 I came to realize that I was barking at the wrong tree, Seems like hikari is very reliable when it comes to connection leak. 我开始意识到我在错误的树上吠叫,似乎hikari在连接泄漏方面非常可靠。 The problem is when amazon aws ec2 instance is stealing some of my cpu and is even greater than what i thought. 问题是当amazon aws ec2实例正在窃取我的一些cpu并且甚至比我想象的更大。 So after the cpu goes up 99%, Connection leak is detected even though my codes clearly closed it in finally block. 因此,在cpu上升99%之后,即使我的代码在finally块中清楚地关闭它,也会检测到连接泄漏。 So the problem lies with the machine. 所以问题在于机器。

I thank you for all who participated to answer. 感谢所有参与回答的人。

通过“堆栈跟踪”遍历代码,它会引导您进行非关闭连接或超过阈值的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM