简体   繁体   English

急于初始化连接池和自定义超时值

[英]Eager Initializing Connection Pool & Custom Timeout Value

I'm using the Tomcat JDBC Connection Pool (which is the Spring Boot default) to manage connections to my PostgreSQL cluster, and I just noticed that the pool is created only when the very first query is made. 我正在使用Tomcat JDBC连接池(这是Spring Boot的默认设置)来管理与PostgreSQL集群的连接,我只是注意到仅在进行第一个查询时才创建该池。 My question is twofold: 我的问题是双重的:

  1. Is there any elegant way to force the pool to be created eagerly (ie, when starting the application)? 有什么优雅的方法可以强制创建池(即,启动应用程序时)? I believe that executing a simple query upon startup would do the trick, but I'd prefer a more elegant way if available. 我相信在启动时执行一个简单的查询就可以解决问题,但是我更喜欢一种更优雅的方式(如果有)。
  2. During one of my tests I used iptables to drop all traffic directed at the PostgreSQL cluster. 在我的一项测试中,我使用iptables丢弃了所有针对PostgreSQL集群的流量。 This caused the first query to last for about 127 seconds before failing with the message Unable to create initial connections of pool . 这导致第一个查询持续约127秒,然后失败,并显示消息“ Unable to create initial connections of pool 127 seconds is way too much. 127秒太多了。 Is there any way I can set a lower value for the timeout? 有什么办法可以为超时设置较低的值? I've read the docs but could not conclude much. 我已经阅读了文档,但总结不多。

Well, for your first question, I can only think 2 methods: 好吧,对于您的第一个问题,我只能考虑以下两种方法:

For your second question; 关于第二个问题; if you choose second approach for first question, than it'll automatically resolved. 如果您对第一个问题选择第二种方法,它将自动解决。 But you can always set 但是你总是可以设置

spring.datasouce.max-wait spring.datasouce.max-wait

parameter. 参数。 In the Tomcat Pool doc it says 在Tomcat Pool文档中说

(int) The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception. (int)在引发异常之前,池将等待(无可用连接时)连接返回的最大毫秒数。 Default value is 30000 (30 seconds) 默认值为30000(30秒)

but in your case, it's 127 seconds, which is strange.. 但您的情况是127秒,这很奇怪。

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

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