我们是 springboot1.x 的应用 用的自带的数据库连接池就是 tomcat,数据库用的是 oracle,现在发生了一些奇怪的事就是初始化数据库连接池的时候可能会卡在创建连接那一步,但是重启可能就好了,也就是说不是必然出现的,之前不知道是卡在数据库创建连接这里,后来是看了 jstack 才知道,所有线程都在等着创建连接,现在临时的解决方案是项目启动后我主动拿一次连接并打印,如果能拿到就没问题,如果不能拿到就重启,以此来判断项目是否正常启动 下边是主动拿连接时候的堆栈日志
"main" #1 prio=5 os_prio=0 tid=0x00007f4868009800 nid=0x2800 runnable [0x00007f486ebad000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:197)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
- locked <0x0000000790329aa0> (a java.lang.Object)
at oracle.net.nt.TimeoutSocketChannel.read(TimeoutSocketChannel.java:144)
at oracle.net.ns.NIOHeader.readHeaderBuffer(NIOHeader.java:82)
at oracle.net.ns.NIOPacket.readNIOPacket(NIOPacket.java:252)
at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:118)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:317)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1438)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:518)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:688)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39)
at oracle.jdbc.driver.OracleDriver.connect$original$HFi5AXBw(OracleDriver.java:691)
at oracle.jdbc.driver.OracleDriver.connect$original$HFi5AXBw$accessor$yuxZSb5R(OracleDriver.java)
at oracle.jdbc.driver.OracleDriver$auxiliary$nsJu79Fa.call(Unknown Source)
at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:86)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:319)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:739)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:671)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:483)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
- locked <0x00000006c8e3ae18> (a org.apache.tomcat.jdbc.pool.DataSource)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at
应该是卡在了 sun.nio.ch.FileDispatcherImpl.read0 这里,看样子是在等待读数据?是数据库的问题还是连接池的问题,或者是驱动的问题,现在我不知道该怎么继续排查了,有没有大神给点建议,万分感谢
1
gz911122 2020-07-03 13:41:03 +08:00
随机种子数问题么
|
2
hantsy 2020-07-03 14:00:05 +08:00
首先确认一下你是 Jar 部署,还是 War 部署。
1. 如果是 Jar 部署,Embedded 方式,Spring Boot 2 。0 后会自已加入 Hikari 配置。 2,如果是 War 部署,最近几代的 Tomcat 应该用上了 Commons Pool2,性能非常不错。最好用 JNDI 连接。把 DataSource 配置在 Tomcat 中,资源进行一步优化。https://github.com/hantsy/angularjs-springmvc-sample/blob/master/src/main/java/com/hantsylabs/restexample/springmvc/config/DataSourceConfig.java#L53-L62 |
3
yangyuhan12138 OP |
4
yangyuhan12138 OP 别沉 大神帮忙看看
|