【发布时间】: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