Bugs item #796585, was opened at 2003-08-28 19:42
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=796585&group_id=22866
Category: JBossServer
Group: v4.0
Status: Open
Resolution: None
Priority: 5
Submitted By: Craig Munday (cmunday)
Assigned to: Nobody/Anonymous (nobody)
Summary: PreparedStatement leak in HiLoKeyGenerator.java
Initial Comment:
Hi,
There is a Statement that does not get closed and is
left to be finialized within the following method (included
below) from the HiLoKeyGenerator class.
The statement create by:
stmt = con.prepareStatement(nextKeyQuery);
leaks because the variable "stmt" is re-assigned with:
stmt = con.prepareStatement(updateStmt);
This second statement is closed within the finally clause
but the first one is never closed and should be
Cheers,
Craig.
public synchronized Object generateKey()
{
if(lo < hi)
return new Integer(lo++);
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
Transaction currentTx = null;
try
{
currentTx = tm.suspend();
tm.begin();
con = datasource.getConnection();
int rowsUpdated;
do
{
if(isDebugEnabled) log.debug("Executing SQL: "
+ nextKeyQuery);
stmt = con.prepareStatement(nextKeyQuery);
rs = stmt.executeQuery();
if(!rs.next())
throw new Exception("Couldn't read next key:
ResultSet is empty.");
lo = rs.getInt(1);
hi = lo + blockSize;
if(isDebugEnabled)
log.debug("Executing SQL: " + updateStmt
+ " [p1=" + hi + ",p2=" + lo + "]");
stmt = con.prepareStatement(updateStmt);
stmt.setInt(1, hi);
stmt.setInt(2, lo);
rowsUpdated = stmt.executeUpdate();
}
while(rowsUpdated == 0);
tm.commit();
}
catch(Exception e)
{
log.error("Error fetching next key:", e);
try
{
tm.rollback();
}
catch(SystemException se)
{
log.error("Couldn't rollback transaction: ", se);
}
}
finally
{
JDBCUtil.safeClose(rs);
JDBCUtil.safeClose(stmt);
JDBCUtil.safeClose(con);
if(currentTx != null)
{
try
{
tm.resume(currentTx);
}
catch(InvalidTransactionException ite)
{
log.error("Invalid transaction: ", ite);
}
catch(SystemException se)
{
log.error("Unexpected error: ", se);
}
}
}
return new Integer(lo++);
}
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=796585&group_id=22866
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development