views:

311

answers:

1

Hey all,

I have the following method being called in a Java EE web application.

public static void submitToPending()
{
    Db db;
    ResultSet rs;

    try
    {
        db = new Db("Database.properties");

        rs = db.issueQuery(getDescriptorList());

        while (rs.next())
        {
            db.insertApplicationData(rs.getString("Id"));
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        db = null;
        rs = null;
    }
}

This is an abbreviated snippet of code I am running to insert about 40,000 new records into a SQL Server 2000 database. This code is executed from a JSP that is hosted on a Solaris 10 server in production. Prior to this year, this code only had to process about 18,000 records, and it worked flawlessly. This year there were some updates made and, to spare details, now processes roughly 40,000 records.

During development I test this on the same database used in production (as the record sets do not conflict) from my Windows PC, from a Tomcat server running inside of Eclipse. Everything works correctly, and all 40,000 or so records make it to the database.

When I installed the site to the production server and ran a test I noticed that over halfway through the process was failing, with the following exception message:

com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerStatement.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.checkClosed(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.next(Unknown Source) at (ClassNameOmittedToProtectTheInnocent.java:74)

The SQL Server is set to unlimited simulataneous connections, unlimited timeout. Assuming my code in class Db is OK (since it is working on the Windows side of things and, up until the data increase, had been performing well on the Solaris side) what are some ideas to start checking out?

I tried tracing the SQL Server to see if something was happening with the connections, but it appears to be alive even after the stack trace is written.

If I can provide any additional information, please let me know. I'll do the best I can to help.

A: 

I'm suspicious of your setting your database and result set reference to null without closing them. I would explicitly close these (if you have a connection pool, closing a connection doesn't actually close it, but acts as a signal to return the connection to the pool).

I'm guessing that you're running into a resource limit such as the maximum number of open file descriptors per process, and the failure to close a result set/connection will be the source of this issue.

Brian Agnew
Even though those calls are in the finally block? This is failing at the db.insertApplicationData() method call.
KG
Is there not a chance that another piece of code running elsewhere with a similar bad handling of its JDBC objects is causing you this problem here, or do you have exclusive db access with this?
banjollity
@KG - my point is that you're not closing/freeing resources properly, so that will cause you problems later on
Brian Agnew
@banjollity - Good point. I will investigate further.
KG