简体   繁体   English

使用executorService执行oracle查询时,java线程挂起

[英]java thread hangs while using executorService executing a oracle query

"pool-11-thread-1" prio=10 tid=0x0a974c00 nid=0x7210 runnable [0x3f3ad000]
   java.lang.Thread.State: RUNNABLE
  at oracle.jdbc.driver.T2CStatement.t2cDefineExecuteFetch(Native Method)
  at oracle.jdbc.driver.T2CPreparedStatement.doDefineExecuteFetch(T2CPreparedStatement.java:878)
  at oracle.jdbc.driver.T2CPreparedStatement.executeForRows(T2CPreparedStatement.java:760)
  at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1062)
  at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1126)
  at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
  at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3445)
  - locked <0x69579fb0> (a oracle.jdbc.driver.T2CPreparedStatement)
  - locked <0x66157d68> (a oracle.jdbc.driver.T2CConnection)
  at org.jboss.resource.adapter.jdbc.CachedPreparedStatement.execute(CachedPreparedStatement.java:216)
  at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:209)
  at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:180)
  at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
  at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
  at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
  at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:561)
  at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:536)
  at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:93)
  at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:273)
  at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
  at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:271)
  at com.alipay.bipgw.common.dal.bankchannel.ibatis.IbatisBipBusiOrderDAO.queryOrderOutTime(IbatisBipBusiOrderDAO.java:319)
  at sun.reflect.GeneratedMethodAccessor3333.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
  at com.alipay.bipgw.common.dal.monitor.DalMonitorInterceptor.invoke(DalMonitorInterceptor.java:60)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
  at $Proxy79.queryOrderOutTime(Unknown Source)
  at com.alipay.bipgw.prodcore.repository.impl.BusiOrderRepositoryImpl.queryOrderOutTime(BusiOrderRepositoryImpl.java:402)
  at com.alipay.bipgw.prodcore.listener.ProdStatusChangeTimeoutTaskListener.execute(ProdStatusChangeTimeoutTaskListener.java:148)
  at com.alipay.bipgw.prodcore.listener.ProdStatusChangeTimeoutTaskListener.access$000(ProdStatusChangeTimeoutTaskListener.java:60)
  at com.alipay.bipgw.prodcore.listener.ProdStatusChangeTimeoutTaskListener$1.run(ProdStatusChangeTimeoutTaskListener.java:104)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  at java.lang.Thread.run(Thread.java:662)

the java programm like this : 这样的java程序:

public void onUniformEvent(UniformEvent message, UniformEventContext uContext) {
    try {
        // single thread running
        service.execute(new Runnable() {
            public void run() {
                try{
                    execute();
                }catch(Exception e ){
                    logger.error("working error",e);
                }

            }
        });
    } catch (RejectedExecutionException e) {
        logger.error("ProdStatusChangeTimeoutTaskListener:error", e);
    } catch (Exception e) {
        logger.error("ProdStatusChangeTimeoutTaskListener:error", e);
    }

}
 //omit the body
 private void execute() {.....}

and the execute method will not start any thread. 并且execute方法将不会启动任何线程。

in two days i dump several thread dump 2013-03-04 16:54:12 在两天内我转储了几个线程转储2013-03-04 16:54:12

- locked <0x695f91f0> (a oracle.jdbc.driver.T2CPreparedStatement)
- locked <0x6615a2d0> (a oracle.jdbc.driver.T2CConnection)  

2013-03-04 17:20:53 2013-03-04 17:20:53

- locked <0x695f91f0> (a oracle.jdbc.driver.T2CPreparedStatement)
- locked <0x6615a2d0> (a oracle.jdbc.driver.T2CConnection)

2013-03-05 10:58:30 2013-03-05 10:58:30

- locked <0x6957bec8> (a oracle.jdbc.driver.T2CPreparedStatement)
- locked <0x66157e90> (a oracle.jdbc.driver.T2CConnection)

2013-03-05 17:16:31 2013-03-05 17:16:31

- locked <0x69579fb0> (a oracle.jdbc.driver.T2CPreparedStatement)
- locked <0x66157d68> (a oracle.jdbc.driver.T2CConnection)

seems like the lock hold by jdbc client has changed, but the first two in 2013-03-04 16:54:12 and 2013-03-04 17:20:53, they are the same 似乎jdbc客户端的锁定保持已更改,但是前两个在2013-03-04 16:54:12和2013-03-04 17:20:53上是相同的

I am using a Excutors.newSingleThreadExecutor() doing a query job in backgroud, and the following task will be submit to this executor Service in 20 minutes interval, but the work thread seems to hangs while executing the query , so the following task will not be executed. 我正在使用Excutors.newSingleThreadExecutor()在backgroud中执行查询作业,并且以下任务将在20分钟的间隔内提交给此执行器服务,但是执行查询时工作线程似乎挂起,因此以下任务不会被执行。 It last for several days , no exception occur and no log output at all, somebody can help me ? 它持续了几天,没有异常,也没有日志输出,有人可以帮助我吗? thanks 谢谢

The problem is likely to lie in your actual query - is it a long running task? 问题可能出在您的实际查询中-这是一项长期运行的任务吗? Do you know how long on average it takes to complete? 您知道平均需要多长时间?

Its possible (but this is dependent on the query itself) that a previous query is locking tables which in turn block later ones. 前一个查询锁定表的可能性(但这取决于查询本身),从而又锁定了后面的表。

The first thing I would do it to verify that the query does indeed complete within 20 minutes, and does so consistently. 我要做的第一件事是验证查询确实在20分钟内完成,并且始终如一。 After you know that it does you can then investigate other possible causes for the hanging behavior you're seeing. 知道它确实存在之后,您就可以调查所看到的挂起行为的其他可能原因。

When the query is running I'd also suggest that you check the explain plan for your query (see what its doing - whats taking the most time etc). 当查询运行时,我还建议您检查查询的解释计划(查看其执行情况-花费最多的时间等)。 I'd also check that the relevant statistics are up to date (perhaps less of an issue on newer versions of Oracle) 我还要检查相关的统计信息是否最新(也许在Oracle的较新版本中问题不大)

This problem has been solved~ after several real time executes , out dba monitor the db server side, and find that the query time is 210s which execeeds the query-out-time(180s), but the cancel request of the stamentent may not be effective and the db server may not response to that request . 这个问题已经解决了〜在几次实时执行后,dba监视数据库服务器端,并发现执行查询查询时间(180s)的查询时间是210s,但是可能不会取消子程序的取消请求有效,数据库服务器可能不会响应该请求。 so the thread which porform the original query hangs. 因此执行原始查询的线程将挂起。 the similar situation see [When I call PreparedStatement.cancel() in a JDBC application, does it actually kill it in an Oracle database? 类似的情况,请参见[当我在JDBC应用程序中调用PreparedStatement.cancel()时,它实际上是否在Oracle数据库中将其杀死?

the solution can been done by following: add sqlprofile to the target table,and make sql using skip scan to short the query time. 该解决方案可以通过以下操作来完成:将sqlprofile添加到目标表,并使用跳过扫描使sql缩短查询时间。

but the deepest reason why hanging will occur is still unknown. 但是,发生挂起的最深层原因仍然未知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用JNDI库执行DNS查询时线程挂起 - Thread hangs while executing DNS query employing JNDI library 从Java类执行Oracle过程时线程被阻塞 - BLOCKED thread while executing Oracle procedure from Java class 在 Java 中使用 ExecutorService 执行第一个可运行对象时是否可以阻止其他可运行对象? - Is it possible to block other runnables while executing the first one, using ExecutorService in Java? ExecutorService Java线程限制 - ExecutorService Java thread limit 使用 ExecutorService 时出现 java.util.ConcurrentModificationException - java.util.ConcurrentModificationException while using ExecutorService 如何在使用具有线程超时功能的ExecutorService时提高性能? - How to improve the performance while using ExecutorService with thread timeout capabilities? ExecutorService和OutOfMemoryError:使用Executor时无法创建新的本机线程 - ExecutorService and OutOfMemoryError: unable to create new native thread while using Executor java ExecutorService newSingleThreadExecutor 是否仅使用一个线程执行所有任务? - Is java ExecutorService newSingleThreadExecutor performs all the tasks using only one Thread? Java ExecutorService 线程终止回调 - Java ExecutorService callback on thread terminate 执行Oracle存储过程后Java进程挂起 - Java process hangs after executing Oracle stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM