Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Random "hangs" of JDBC connections

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
- locked <0x9218a720> (a com.mysql.jdbc.util.ReadAheadInputStream)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2428)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2938)
...

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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
}
 
ice is for people that are not already cool. Chill with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic