【问题标题】:Spring Boot - PoolExhaustedExceptionSpring Boot - PoolExhaustedException
【发布时间】:2017-10-22 10:11:23
【问题描述】:

我最近使用最新的 Spring Boot Starter Framework 重建了我所有的 Spring 4 项目。

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
 </parent>

到目前为止一切正常,除了我在所有重建项目中随机遇到 PoolExhaustedException。

确切的例外是:

org.apache.tomcat.jdbc.pool.PoolExhaustedException: [http-nio-8080-exec-4] Timeout: Pool empty. Unable to fetch a connection in 20 seconds, none available[size:50; busy:50; idle:0; lastwait:20000].

我收到的最后一个异常来自从我的数据库下载文档的控制器:

@RequestMapping(value = "/getDocument/{value}/{text}", method = RequestMethod.GET)
public void get(HttpServletResponse response, @PathVariable String value, @PathVariable String text){
      try {
          Document ufile = documentService.getDocumentByID(Integer.parseInt(value));

          response.setContentType(ufile.getType());
          response.setContentLength(ufile.getContent().length);
          FileCopyUtils.copy(ufile.getContent(), response.getOutputStream());

      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
}

服务:

@Transactional
public Document getDocumentByID(int id) {
    Document r = this.documentDAO.getDocumentByID(id);
    return r;
}

道:

@Transactional
public Document getDocumentByID(int id)
{
    Session session = this.sessionFactory.getCurrentSession();      
    Document p = (Document) session.load(Document.class, new Integer(id));
    return p;
}

我已经尝试使用 @Transactional 对控制器进行注释,这暂时解决了问题,但导致了其他事务错误,因此我不得不将其删除。

我还尝试通过 project.properties too 100 增加池,这只会延迟问题但没有解决问题。

project.properties

spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

【问题讨论】:

    标签: spring hibernate spring-mvc spring-boot


    【解决方案1】:

    不确定具有这些名称的属性是否有任何影响。

    我还尝试设置断点并直接检查 Tomcat 数据源以查看要说服的值(可以在测试中轻松自动装配)。

    查看Spring BootTomcat Datasource Configuration Tests,我看到了一些有趣的选项,例如minEvictableIdleTimeMillistimeBetweenEvictionRunsMillis 和maxWait,它们都以spring.datasource.tomcat. 为前缀,所以试试看。

    【讨论】:

    • 我想我的主要问题是 tomcat 或 hibernate 没有正确关闭我的自动连接会话,但我会检查一下。
    猜你喜欢
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 2014-04-07
    • 2014-04-07
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多