3.1.6 Threading Bug/Issue
Posted by: Jason Winnebeck
Date: February 11, 2005 11:24AM

I'm having a problem with the 3.1.6 driver. From what I understand of the JDBC specification is that all of the methods are supposed to be thread-safe. That means that while I'm executing a prepared statement, another thread could be executing or preparing another. I realize that MySQL driver is allowed to and does serialize requests to the driver, but this seems not to be the case. I have found a situtation where I am trying to execute a prepared statement and prepared one at the same time. It appears through my trace of the stacks that MySQL has sent conflicting commands to the DB. The result is a situation that appears like a deadlock, but is not actually one. The thread getting the ResultSet is waiting for a read that will never happen while the other thread is waiting for the result of the PreparedStatement. Here is a stack trace of the two threads:

Graph DataLoader@794 prio=6, in group "main", status: RUNNING
blocks MissionDetail Loading Thread@691
blocks Thread-7@65e
waiting for Graph DataLoader@78b
read():112, ReadAheadInputStream.java
readFully():1842, MysqlIO.java
reuseAndReadPacket():2345, MysqlIO.java
checkErrorPacket():2788, MysqlIO.java
sendCommand():1534, MysqlIO.java
serverPrepare():1485, ServerPreparedStatement.java
<init>():151, ServerPreparedStatement.java
prepareStatement():1309, Connection.java
prepareStatement():1281, Connection.java

Graph DataLoader@78b prio=6, in group "main", status: RUNNING
blocks Graph DataLoader@794
socketRead0():-1, SocketInputStream.java
read():129, SocketInputStream.java
fill():75, ReadAheadInputStream.java
readFromUnderlyingStreamIfNecessary():94, ReadAheadInputStream.java
read():122, ReadAheadInputStream.java
readFully():1842, MysqlIO.java
readPacket():476, MysqlIO.java
getResultSet():399, MysqlIO.java
readResultsForQueryOrUpdate():1902, MysqlIO.java
readAllResults():1350, MysqlIO.java
serverExecute():1390, ServerPreparedStatement.java
executeInternal():957, ServerPreparedStatement.java
executeQuery():1657, PreparedStatement.java

There are other threads, but none of them are executing code in the com.mysql package.

I am hoping from this stack trace you can see what you need to see. It seems to me that the serialization functionality of the driver is not working and the driver is making an attempt to be doing two things at once. My server is MySQL 4.1.8 version, and my driver 3.1.6, Java is version 1.5u1.

Please advise me if you need more information, but I'm not 100% certain this will occur again because threading is always non-deterministic, so that is why I wanted to capture the stack trace now. We plan to work around this code by not allowing multiple threads to share a connection -- this was on our list of things to do anyway as we want to try to implement streaming result sets when we pull huge data queries.

Jason Winnebeck
Center for Integrated Manufacturing Studies
Rochester Institute of Technology, Rochester NY

Options: ReplyQuote

Written By
3.1.6 Threading Bug/Issue
February 11, 2005 11:24AM
February 11, 2005 01:08PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.