Solved

Set timeout in Informix JDBC connection?

Posted on 2009-07-13
12
5,512 Views
Last Modified: 2013-12-24
Hi experts,

In one of my projects I am having some strange Problems. Even if they occur about every 3-4 Months, I would like to get rid of them.

The problem is that I have a JDBC connection to an Informix database and use this to log changes to my data. Now about every 3-4 Months a JDBC request hangs and never returns.

Is there a way to make the JDBC driver terminate a query if it takes too long? What I want is to set a timeout to about 5 seconds (It's a really simple insert of one row of data).

Chris

PS: Is a thread dump of the hanging thread.
Thread-1022 "[STUCK] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)'" <alive, in native, suspended, priority=1, DAEMON> {

    jrockit.net.SocketNativeIO.readBytesPinned(SocketNativeIO.java:???)

    jrockit.net.SocketNativeIO.socketRead(SocketNativeIO.java:31)

    java.net.SocketInputStream.socketRead0(SocketInputStream.java:???)

    java.net.SocketInputStream.read(SocketInputStream.java:107)

    java.io.BufferedInputStream.fill(BufferedInputStream.java:189)

    java.io.BufferedInputStream.read1(BufferedInputStream.java:247)

    java.io.BufferedInputStream.read(BufferedInputStream.java:304)

    ^-- Holding lock: java.io.BufferedInputStream@23a7b64[thin lock]

    com.informix.asf.IfxDataInputStream.readFully(IfxDataInputStream.java:133)

    com.informix.asf.IfxDataInputStream.readSmallInt(IfxDataInputStream.java:443)

    com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2254)

    com.informix.jdbc.IfxSqli.executeCommand(IfxSqli.java:742)

    com.informix.jdbc.IfxResultSet.b(IfxResultSet.java:259)

    com.informix.jdbc.IfxStatement.c(IfxStatement.java:1241)

    com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:402)

    sun.reflect.GeneratedMethodAccessor978.invoke(Unknown Source)

    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    java.lang.reflect.Method.invoke(Method.java:570)

    org.apache.avalon.excalibur.datasource.AbstractJdbcConnection$ProxiedObject.invoke(AbstractJdbcConnection.java:468)

    $Proxy55.executeUpdate(Unknown Source)

.

.

.

.

.

.

Open in new window

0
Comment
Question by:ChristoferDutz
  • 9
  • 3
12 Comments
 
LVL 6

Expert Comment

by:tangchunfeng
ID: 24838529
I found you use
org.apache.avalon.excalibur.datasource.AbstractJdbcConnection
to manage jdbcConnection,
maybe you can change to use jdbc connection pool managed by weblogic
0
 
LVL 20

Author Comment

by:ChristoferDutz
ID: 24838590
Well I am using a Cocoon application and it is deployed on tomcat in the test environment and on Weblogic on the production environment. I would really like to have both configurations the same. I know the MySQL driver starts a thread monitoring JDBC threads and trminates long running operations. Does something like this exist for Informix? Is there a parameter I can add to the JDBC connection string?
0
 
LVL 6

Expert Comment

by:tangchunfeng
ID: 24845037
what's your version of tomcat/weblogic/informix jdbc/informix server?
0
 
LVL 6

Expert Comment

by:tangchunfeng
ID: 24845104
INFORMIXCONTIME
Sets the timeout period for an attempt to connect to the database server. If a connection attempt does not succeed in this time, the attempt is aborted and a connection error is reported. The default value is 0 seconds. This variable adds timeouts for blocking socket methods and for socket connections.
This parameter is effective in Informix JDBC 3.0.
0
 
LVL 6

Expert Comment

by:tangchunfeng
ID: 24845149
http://forums.sun.com/thread.jspa?threadID=5266195&start=0

By this URL, this may be a  performance problem of db lock.
Ask your DBA to investigate db lock when the thread is stuck.
0
 
LVL 20

Author Comment

by:ChristoferDutz
ID: 24847185
Unfortunately this link didnt help a lot and the Parameter seems to affect only the connections to the db. The connection is not an issue here (by the way ... the default timeout is 60 seconds ... I know this because initially we were having problems with the connection timeout). Indeed the problem was with the Database Server undfortunately I couldn't find a way to recover the blocked thread (which blocks some important system resources).

The solution I have come up with was to create a sort of "TimebombThread" that sends the Thread that creates it a Signal if it is not disabled within 5 seconds. After processing the statement the timebomb is manually disabled. This sort of does the trick, but I would have liked to have something like this in the driver as it is in MySQL.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:tangchunfeng
ID: 24866728
I find a parameter in weblogic connection pool :  Statement Timeout
If you change to use weblogic managed connection pool, you will have the funcationality of "TimebombThread"
0
 
LVL 6

Accepted Solution

by:
tangchunfeng earned 250 total points
ID: 24866744

And if you use Informix JDBC 3.00.JC3 and above,
you can add Statement.setQueryTimeout()  to your code.

http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.docnotes.doc/uc5/jdbc_docnotes_3.00.html
0
 
LVL 6

Expert Comment

by:tangchunfeng
ID: 24867225
I tried with some Java program.

// 1 second
stmt.setQueryTimeout(1);

and execute a long running query, you will get

java.sql.SQLException: Statement interrupted by user.
      at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3204)
      at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3518)
      at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2353)
      at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2269)
      at com.informix.jdbc.IfxSqli.a(IfxSqli.java:1532)
      at com.informix.jdbc.IfxSqli.executeStatementQuery(IfxSqli.java:1471)
      at com.informix.jdbc.IfxSqli.executeStatementQuery(IfxSqli.java:1401)
      at com.informix.jdbc.IfxResultSet.a(IfxResultSet.java:204)
      at com.informix.jdbc.IfxStatement.executeQueryImpl(IfxStatement.java:1212)
      at com.informix.jdbc.IfxStatement.executeQuery(IfxStatement.java:202)
      at jdbc.InformixJdbcSelect.main(InformixJdbcSelect.java:35)
Caused by: java.sql.SQLException: ISAM error: Interrupted ISAM call
      at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:373)
      at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3523)
      ... 9 more
0
 
LVL 6

Expert Comment

by:tangchunfeng
ID: 24867301
and you can add "QueryTimeout=5" to the informix jdbc url
0
 
LVL 20

Author Closing Comment

by:ChristoferDutz
ID: 31602731
Hi tangchunfeng,

thanks for that ... I remember having a look at that method a few years ago ... unfortunately in those days it was unsupported. My customer updated to a new release of Informix and now I can use it ... thanks for that hint :-)
0
 
LVL 6

Expert Comment

by:tangchunfeng
ID: 24867351
"jdbc:informix-sqli://192.168.1.180:9088/benchmark:INFORMIXSERVER=demo_on;user=informix;password=informix;QueryTimeout=1"

seems not working, just forget it

although it's documented by bea
http://edocs.bea.com/wls/docs103/jdbc_drivers/informix.html

I'm using INFORMIX 11.50.UC4 and
IBM Informix JDBC Driver Version 3.00.JC3
IBM Informix JDBC Driver Version 3.50.JC4DE( included with 11.50.UC4)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now