hikaripool连接保持,HikariPool-1 – 连接不可用,请求超时后[通俗易懂]

hikaripool连接保持,HikariPool-1 – 连接不可用,请求超时后[通俗易懂]I’musingHikariCP2.4.7forconnectionpool.EverythingisfinejustafterstartingtheapplicationbutaftersometimewithoutinvokinggetConnection()IgetthiserrorwhenI’mtryingtogetConnect…

大家好,又见面了,我是你们的朋友全栈君。

hikaripool连接保持,HikariPool-1 - 连接不可用,请求超时后[通俗易懂]

I’m using HikariCP 2.4.7 for connection pool. Everything is fine just after starting the application but after some time without invoking getConnection() I get this error when I’m trying to getConnection():

java.sql.SQLTransientConnectionException: HikariPool-1 – Connection is not available, request timed out after 42734ms.

at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:555)

at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:188)

at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:147)

at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:99)

at pl.airly.database.ComplexOperations.getSensorDataFromArea(ComplexOperations.java:310)

at pl.airly.database.ComplexOperations.getMeasurementsInAreaWithinTimeFrame(ComplexOperations.java:201)

at pl.airly.ResponseGenerator.getResponseAdequateToRequest(ResponseGenerator.java:139)

at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)

at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)

at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:745)

During startup I’m initializing HikariDataSource:

hikariDataSource = new HikariDataSource();

hikariDataSource.setDriverClassName(“org.postgresql.Driver”);

hikariDataSource.setUsername(DATABASE_USER_NAME);

hikariDataSource.setPassword(DATABASE_PASSWORD);

hikariDataSource.setJdbcUrl(DATABASE_URL);

hikariDataSource.setLeakDetectionThreshold(5000);

And then I’m using it like this:

try(java.sql.Connection conn = Connection.hikariDataSource.getConnection()) {

Record1 record1 = DSL.using(conn).select(SENSOR.ID) //jOOQ

.from(SENSOR)

.where(SENSOR.ID.equal(1))

.limit(1)

.fetchOne();

Debug.println(record1.getValue(0).toString());

} catch (SQLException e) {

e.printStackTrace();

}

What am I doing wrong? How to troubleshoot this problem?

Edit:

Adding this solves the problem:

hikariDataSource.setIdleTimeout(60000);

hikariDataSource.setConnectionTimeout(60000);

hikariDataSource.setValidationTimeout(3000);

hikariDataSource.setLoginTimeout(5);

hikariDataSource.setMaxLifetime(60000);

It may be something connected with the server closing connections before HikariCP does but I’m not sure. Any comment on this would be appreciated.

解决方案

I start by saying than i am not a Java programmer, you can try to close jOOQ DSL also:

try(java.sql.Connection conn = Connection.hikariDataSource.getConnection()) {

try (Record1 record1 = DSL.using(conn).select(SENSOR.ID)) {

.from(SENSOR)

.where(SENSOR.ID.equal(1))

.limit(1)

.fetchOne();

Debug.println(record1.getValue(0).toString());

} catch (Exception e) {

e.printStackTrace();

}

} catch (SQLException e) {

e.printStackTrace();

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/152381.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 对象

    对象

  • WinServer2012配置AD域

    WinServer2012配置AD域WinServer2012配置AD域一、修改域控主机网卡IP,配置为静态IP,DNS配置为本机,并修改计算机名修改计算机名后需要重启注:若发现域控主机外部无法ping通请注意修改防火墙配置二、安装AD服务,将主机作为域控主机点击添加功能后,单击下一步随后添加功能组件,根据需求添加,点击下一步等待安装完成安装完成点击关闭安装完成后,点击上方的通知选择将此服务器提升为域控制器选择添加新林,设置好域名后点击下一步设置域还原密码,用于当域主机出现故障

  • phpstorm2021永久激活码-激活码分享

    (phpstorm2021永久激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.cn/100143.html9ZHRNTE33T-eyJsaWN…

  • php源码中powerby,如何去掉织梦dedecms底部调用cfg_powerby的power by dedecms

    php源码中powerby,如何去掉织梦dedecms底部调用cfg_powerby的power by dedecms我们平常使用织梦后台做建站的时候都会发现,如果调用版权信息的时候,在底部使用cfg_powerby调用的时候出现powerbydedecms的链接信息,而这个链接又是个导出链接,我们怎么样才能一劳永逸的直接去掉呐,下面站优云小编就跟大家分享一下。在之前版本我们的解决方法是:1、去掉{dede:globalname=’cfg_powerby’/};2、进入后台,点击系统->系统基本设…

  • scrapy+xpath爬取不可描述网站[通俗易懂]

    scrapy+xpath爬取不可描述网站[通俗易懂]今天来爬一个让人很有动力的网站,网址就不便放上来了,看看有没有有缘人能得知了还是先来items.pyimportscrapyclassAvmooItem(scrapy.Item):#definethefieldsforyouritemherelike:#name=scrapy.Field()name=scrapy.Field()

  • 软件介绍网站:“软矿”x-berry「建议收藏」

    软件介绍网站:“软矿”x-berry「建议收藏」今天发现了一个推荐软件的网站叫做“软矿”做的很不错。页面简洁,大方,内容也很新。我查询的是虚拟机相关的软件和技术,里面对VMware和Virtualbox的介绍都比较丰富。

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号