java - Spring 应用程序在 200 个数据库连接时自行关闭
问题描述
在一个遗留的生产应用程序中,我们遇到了应用程序崩溃的问题,因为它没有连接(默认为 100 个连接)作为临时解决方案,我们决定将可用连接增加到 500 个,但是当应用程序达到 200 个连接时它就停止了本身,日志上没有错误,就像简单的关闭一样。
我添加了一些每 15 秒生成的日志,以便清楚地查看连接的行为,这些日志打印空闲连接和活动连接以及数据源属性的完整对象。在应用程序关闭之前添加的以下日志:
Datasource idle connections: 0, active connections: 200
数据源属性:org.apache.tomcat.jdbc.pool.DataSource@20b2475a{ConnectionPool[defaultAutoCommit=null; 默认只读=空;默认交易隔离=-1;默认目录=空;driverClassName=com.mysql.jdbc.Driver; 最大活动=500;最大空闲=500;分钟空闲=10;初始大小=10;最大等待=30000;testOnBorrow=真;测试返回=假;timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=假;测试连接=假;密码=********;url=jdbc:mysql://127.0.0.1:3306/db_name?createDatabaseIfNotExist=true; 用户名=用户名;验证查询=选择 1;验证查询超时=-1;验证器类名=空;验证间隔=3000;accessToUnderlyingConnectionAllowed=true; 删除放弃=假;removeAbandonedTimeout=60; 日志放弃=假;连接属性=空;初始化SQL=空;jdbc拦截器=空;jmxEnabled=真;公平队列=真;使用等于=真;放弃当百分比满=0;最大年龄=0;使用锁=假;数据源=空;数据源JNDI=空;怀疑超时=0;备用用户名允许=假;提交返回=假;回滚返回=假;useDisposableConnectionFacade=true; 日志验证错误=假;传播中断状态=假;忽略异常OnPreLoad=假;}
之后应用程序自行关闭,我发现以下日志之前没有错误:
2021-02-03 20:23:02.618 INFO 1 --- [ Thread-4] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@8807e25: startup date [Wed Feb 03 19:49:09 GMT 2021]; root of context hierarchy
2021-02-03 20:23:02.623 INFO 1 --- [ Thread-4] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2021-02-03 20:23:02.643 INFO 1 --- [ Thread-4] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2021-02-03 20:23:02.647 INFO 1 --- [ Thread-4] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
一些相关的依赖项及其版本:
org.springframework:spring-webmvc:jar:4.3.6.RELEASE:compile
org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.1.RELEASE:compile
org.apache.tomcat:tomcat-jdbc:jar:8.5.11:compile
org.hibernate:hibernate-core:jar:5.0.11.Final:compile
org.springframework.data:spring-data-jpa:jar:1.11.0.RELEASE:compile
org.springframework.boot:spring-boot-starter-web:jar:1.5.1.RELEASE:compile
org.liquibase:liquibase-core:jar:3.5.1:compile
org.liquibase.ext:liquibase-hibernate5:jar:3.6:compile
最后,我的问题是寻求帮助以了解为什么应用程序会自行关闭以及如何修复它以使其能够达到 500 个连接?
解决方案
推荐阅读
- visual-studio-code - Vim:跨多行插入同一列
- python - 读取 JSON 文件以获得最高分辨率的图像 (Last.FM)
- android - 如何修改所有 android web 视图请求的标头(包括带有正文的请求,例如 post)?
- android - 如何获取一个字符串然后在 EditText 上显示它
- swift - 无法将“addItem.Product”类型的值转换为预期的参数类型“productsCollectionViewCell.Product”
- javascript - 处理nodeJs服务器中c程序返回的数组
- elasticsearch - ElasticSearch - 最后一个事件未上传到 kibana
- r - 巴特沃斯滤波器导致信号开始时出现极端异常值
- opencv - 如何结合 PnP、ICP 和直接法的非线性方法?
- unity3d - 在运行期间更改统一项目设置