我们在payara 5.2020服务器上有一个J2EE应用程序,它执行了一个长时间运行的查询(PL/SQL,执行了几个小时)。为了避免超时异常,我们在StatementLevel使用以下语句:
statement.setQueryTimeout(0);
使用Oracle jdbc驱动程序版本12 c时,这是可行的,但当我们迁移到Oracle 18 c时,我们将驱动程序更改为版本18 c,查询执行在15分钟后停止,但出现此异常。代码适用于Oracle 12,Oracle 18是驱动程序jar中的更改导致了问题。该问题已在Linux和Windows计算机中重现:
2021-06-14T07:50:01.762+0200|SEVERE: java.sql.SQLRecoverableException: Error de E/S: Socket read interrupted
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:946)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1136)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3640)
at oracle.jdbc.driver.T4CCallableStatement.executeInternal(T4CCallableStatement.java:1318)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3752)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4242)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1079)
at com.sun.gjc.spi.base.PreparedStatementWrapper.execute(PreparedStatementWrapper.java:532)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.sun.gjc.spi.jdbc40.ProfiledConnectionWrapper40$1.invoke(ProfiledConnectionWrapper40.java:437)
at com.sun.proxy.$Proxy324.execute(Unknown Source)
at org.apache.jsp.index_jsp.callPL(index_jsp.java:49)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:108)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1636)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:259)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:757)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:158)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:520)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:217)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.io.InterruptedIOException: Socket read interrupted
at oracle.net.nt.TimeoutSocketChannel.handleInterrupt(TimeoutSocketChannel.java:262)
at oracle.net.nt.TimeoutSocketChannel.read(TimeoutSocketChannel.java:184)
at oracle.net.ns.NSProtocolNIO.doSocketRead(NSProtocolNIO.java:544)
at oracle.net.ns.NIOPacket.readHeader(NIOPacket.java:234)
at oracle.net.ns.NIOPacket.readPacketFromSocketChannel(NIOPacket.java:174)
at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:122)
at oracle.net.ns.NIOPacket.readFromSocketChannel(NIOPacket.java:100)
at oracle.net.ns.NIONSDataChannel.readDataFromSocketChannel(NIONSDataChannel.java:86)
at oracle.jdbc.driver.T4CMAREngineNIO.prepareForUnmarshall(T4CMAREngineNIO.java:762)
at oracle.jdbc.driver.T4CMAREngineNIO.unmarshalUB1(T4CMAREngineNIO.java:427)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:394)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:255)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:610)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:249)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:82)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:924)
传输层似乎已经迁移到java.nio,setQueryTimeout方法不再是
我们尝试过的事情:
1.在payara控制台的JDBC连接池高级属性屏幕中将默认语句超时设置为-1。
1.尝试直接在连接中使用conn.setNetworkTimeout(Executors.newFixedThreadPool(1),0)设置时间没有任何效果。
1.在不同的来源中,我们发现下面的这些属性应该会影响网络超时评估。我们将它们设置为payara启动的JVM属性(-Doracle.net.CONNECT_TIMEOUT=xxx)和JDBC连接池属性,两种情况的值都是0和-1。在任何情况下都不起作用。
- oracle.net.CONNECT_TIMEOUT
- oracle.net.READ_TIMEOUT
- oracle.jdbc.ReadTimeout
资料来源:
- Oracle 18c Net services best practices
- Oracle 18 c java jdbc reference. E.1.5使用JDBC和防火墙
4.-由于我们通过payara DataSource池访问DataSource,因此无法将com.sun.gjc.spi.jdbc40.DataSource40(由payara提供的类)转换为OracleDataSource,但我们通过编程创建了DataSorce来设置连接属性,如下所示,并设置上图中所示的属性,但它不起作用:
public static Properties oracleProperties() {
// Already tried -1 and 0
Properties properties = new Properties();
properties.put("Oracle.net.CONNECT_TIMEOUT", 0);
properties.put("Oracle.net.READ_TIMEOUT", 0);
properties.put("Oracle.jdbc.ReadTimeout", 0);
return properties;
}
public static OracleDataSource createDataSource() throws Exception {
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@itauc4602x:1521/BDExp");
ods.setUser("enevac");
ods.setPassword("enevac");
ods.setDataSourceName("OracleXADataSource");
ods.setLoginTimeout(0);
// default connection properties to avoid timeoutException
ods.setConnectionProperties(oracleProperties());
return ods;
}
1.有人遇到过这个问题吗?有没有关于如何避免timeOut限制的想法?
1.为什么是15分钟?,according to the reference,oracle .NET.ReadTimeout的默认值是10分钟。
更新:为了更详细地解释为什么我认为问题出在驱动程序中,以及为什么我放弃了异常的其他可能来源,我假设超时可以从三个来源引发:
- 网络超时:我放弃它是因为我正在测试一个payara服务器在我的本地机器上对开发数据库,没有防火墙之间。
- 数据库服务器:DBA已经检查了Oracle网络服务配置,并且没有限制设置来解释15分钟的缩短。此外,在这些情况下,将预期SQLException,并带有某种ORA-xxx错误代码。
- JDBC:这可以在连接级别,语句级别和事务级别进行设置。正如我在开始时所说,代码与Oracle 12 c驱动程序一起工作,针对Oracle 12和Oracle 18服务器,是驱动程序的jar更改导致代码停止工作。
3条答案
按热度按时间bihw5rsg1#
最后,在payara池中配置OracleDataSource的“connectionProperties”自定义属性时,该问题得到了修复。正如@ibre5041指出的,设置属性oracle.jdbc.javaNetNio=false会更改驱动程序使用的传输层,它将开始作为oracle 12 c以前的版本工作。
根据Oracle reference,OracleDataSource实现者可以接收作为java.util.Properties对象的连接属性。
表8-2 Oracle扩展数据源属性
要在Payara管理控制台中为jdbc池设置多值属性,您必须将属性设置为(prop 1 = value 1,prop 2 = value 2),(Thank you again Ondro Mihályi)。因此,在我们的示例中,我们设置:
connectionProperties =(oracle.jdbc.ReadTimeout=0,oracle.jdbc.javaNetNio=false)
作为使用Oracle 18 c jdbc驱动程序的工作和不工作的总结(每个步骤单独测试):
statement.setQueryTimeout(0)
conn.setNetworkTimeout(Executors.newFixedThreadPool(1),timeout(ms))
因此,这使得查询在10秒后停止:- 多拉克网连接超时=10000 -多拉克网读取超时=10000 -多拉克网jdbc读取超时=10000
但这在15分钟后停止:-Doracle.net.CONNECT_TIMEOUT=-1 -Doracle.net.READ_TIMEOUT=-1 -Doracle.jdbc.ReadTimeout=-1
无论如何,我们打开了Oracle的支持问题,因为jdbc API语句。setQueryTimeout(0)应该在无需配置数据源的情况下工作,我会在案例关闭时放置响应。
tyg4sfes2#
由于默认的tcp连接超时,查询执行可能会停止。能否将keepalive属性“oracle.net.keepAlive”设置为“true”并进行验证?
gg58donl3#
根据文档ID 2612009.1 https://support.oracle.com/knowledge/Middleware/2612009_1.html,所有以www.example.com开始的Oracle JDBC驱动程序12.2.0.1有一个bug,并且有解决方法。启动应用程序时,您需要设置属性-Doracle.jdbc.javaNetNio=false