File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Random Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Random "hangs" of JDBC connections" Watch "Random "hangs" of JDBC connections" New topic

Random "hangs" of JDBC connections

Martin Wingert

Joined: Oct 10, 2005
Posts: 16
I have a Java application connecting to a MySQL database (> 25 Gb MyISAM Engine) using JDBC mysql-connector-java-5.1.6. When I separate the database and put it on a separate server than the application it hangs in the JDBC driver after a random time and in random parts in the application. The application have a list of database connections that is used in a round-robin fashion. A connection could be used by several threads at the same time if a statement takes enough time so that a used connection is picked by another thread (I have implemented a connection pool, Apache DBCP, but that is not in use on this system yet).

This is some output from the JVM threaddump:

"RequestProcessor-114659" daemon prio=1 tid=0x896b0d30 nid=0x33c runnable [0x83eda000..0x83edb030]
at Method)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(
- locked <0x9218a720> (a com.mysql.jdbc.util.ReadAheadInputStream)
at com.mysql.jdbc.MysqlIO.readFully(
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(

The dump is much longer than this but I think the vital part is here. The thread is waiting on socketRead ie some kind of response from the database server. There is no database query being executed when this happens so it shouldn't wait for a response from the database.

Have anyone else encountered any similar problem? Any ideas on what the problem could be?

I read something about that the use of a jdbc connection from several threads at the same time could trigger these kinds of locks so that is something I will test by deploying a version with a proper database pool.

BR // Martin
David Young

Joined: Apr 01, 2005
Posts: 4
It sounds like a problem of connection leakage. Make sure you have closed the connection object in any cases after commit/execution.

try {
} catch (...) {
} finally {
//close connection here
I agree. Here's the link:
subject: Random "hangs" of JDBC connections
jQuery in Action, 3rd edition