Set timeout in Informix JDBC connection?

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

LVL 20
ChristoferDutzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tangchunfengCommented:
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
ChristoferDutzAuthor Commented:
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
tangchunfengCommented:
what's your version of tomcat/weblogic/informix jdbc/informix server?
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

tangchunfengCommented:
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
tangchunfengCommented:
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
ChristoferDutzAuthor Commented:
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
tangchunfengCommented:
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
tangchunfengCommented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tangchunfengCommented:
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
tangchunfengCommented:
and you can add "QueryTimeout=5" to the informix jdbc url
0
ChristoferDutzAuthor Commented:
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
tangchunfengCommented:
"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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.