tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Would like to monitor memory use offline
Date Fri, 08 Aug 2008 23:07:51 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Richard,

Richard S. Huntrods wrote:
|    public static Vector listLookup(String table) {
| //        Connection connection = null; // connection is managed by a
| connection pool

So, is 'connection' a local or not?

|        Statement statement = null;
|        ResultSet resultSet = null;
|
|        // connection is managed by a connection pool
|        try {
|            if(connection == null) {
|                getConnection();
|            }

If 'connection' is a local, what does 'getConnection' do?

If 'connection' is /not/ a local, then you are asking for threading trouble.

|            if(connection != null) {
|                statement = connection.createStatement();
|                resultSet = statement.executeQuery("SELECT * FROM " +
| table + " ORDER BY idNumber");
|                if(resultSet != null) {
|                    /* process resultSet */
|                    }
|                    resultSet.close();
|                }
|                statement.close();
|            }
|            return /* results Vector */
|        }
|        catch (SQLException sqle) {
|        /* debug messages */
|        }
|        catch (Exception e) {
|        /* debug messages */
|        }
|        finally {
|        /* debug messages */
|            connection = null;

You need to have statement.close() and resultSet.close() in here (in the
finally block), not up above. Also, most database connection pools
require that you call connection.close() to return the connection to the
pool. Are you ever calling connection.close()?

Also, which connection pool do you use?

|        }
|        return null;
|    }
|
| NOTE: by checking debug logs, I can tell that during normal use there
| are NO exceptions occurring, and the finally is NOT getting called - yet
| the memory leak is still going on.

The finally block had /better/ be called: it's a requirement of the JVM
and the language.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkic0ccACgkQ9CaO5/Lv0PCO9gCgvHVnhOhPwIXl0qp1NOYW5Iv8
QigAn01hq4VakqxDOKV239NJujm9t/8b
=9gnQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message