tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "g. rgar" <the.u...@gmail.com>
Subject Re: tomcat eclipse and too many connections
Date Sun, 14 Oct 2012 21:54:13 GMT
Thank you very much for the reply :)

I do not think I leak connections cause I can get the behavior by :
1. starting eclipse
2. starting tomcat in eclipse - the app is deployed
3. making a trivial change in a servlet (adding a space) and saving - the
app is redeployed
4. after some redeployements the exception is thrown (10 in the example
below)

The finally blocks are not needed in the code I posted - if there is an
exception the connection will be null. I do meticulously close the
connection, statement and result set in finally blocks in every DAO method
using the closeResources() method posted.

This is not a DAO class - just the "Connector" class - so to speak

The stack trace I did post - hapilly eclipse redirects the logs to std out
Below I post the logs for the full scenario 2-4 above

The :
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@4809f93a
SessionListener - contextDestroyed

are printouts from a Context Listener I set up - I could add datasource
closing on contextDestroyed easily if :

a. I knew how (to close the data source - I do not think killing the thread
as suggested here :
http://stackoverflow.com/questions/11872316/tomcat-guice-jdbc-memory-leakis
really curing the problem - rather the symptom)
b. this is the issue really

Notice the : SEVERE: The web application [/ted2012] appears to have started
a thread named [Abandoned connection cleanup thread] but has failed to stop
it. This is very likely to create a memory leak.

Googling this I got the impression the datasource should be managed by
tomcat - so what should I do ? there is no close() method for the datasource



Oct 15, 2012 12:31:35 AM org.apache.tomcat.util.digester.SetPropertiesRule
begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting
property 'source' to 'org.eclipse.jst.jee.server:ted2012' did not find a
matching property.
Oct 15, 2012 12:31:35 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Oct 15, 2012 12:31:35 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8443"]
Oct 15, 2012 12:31:35 AM org.apache.tomcat.util.net.NioSelectorPool
getSharedSelector
INFO: Using a shared selector for servlet write/read
Oct 15, 2012 12:31:35 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 840 ms
Oct 15, 2012 12:31:35 AM org.apache.catalina.core.StandardService
startInternal
INFO: Starting service Catalina
Oct 15, 2012 12:31:35 AM org.apache.catalina.core.StandardEngine
startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.30
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@4809f93a
Oct 15, 2012 12:31:37 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Oct 15, 2012 12:31:37 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8443"]
Oct 15, 2012 12:31:37 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1169 ms
Oct 15, 2012 12:32:37 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:32:37 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@365938c8
Oct 15, 2012 12:32:38 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:32:58 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:32:58 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@7a9c8b97
Oct 15, 2012 12:32:58 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:33:08 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:33:08 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@67dcb3bf
Oct 15, 2012 12:33:09 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:33:39 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:33:39 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@1dc8f55d
Oct 15, 2012 12:33:40 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:34:00 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:34:00 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@7bff0922
Oct 15, 2012 12:34:01 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:34:11 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:34:11 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@302e3705
Oct 15, 2012 12:34:11 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:34:21 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:34:21 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@60606400
Oct 15, 2012 12:34:22 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:34:32 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:34:32 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@585d023d
Oct 15, 2012 12:34:33 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:34:43 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:34:43 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@304a6504
Oct 15, 2012 12:34:44 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed
Oct 15, 2012 12:34:54 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] has started
SessionListener - contextDestroyed
Oct 15, 2012 12:34:54 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads
SEVERE: The web application [/ted2012] appears to have started a thread
named [Abandoned connection cleanup thread] but has failed to stop it. This
is very likely to create a memory leak.
Oct 15, 2012 12:34:54 AM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data
source rejected establishment of connection,  message from server: "Too
many connections"
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    at com.mysql.jdbc.Util.getInstance(Util.java:382)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1116)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2338)
    at
com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.GeneratedConstructorAccessor18.newInstance(Unknown
Source)
    at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
    at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
    at
org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:278)
    at
org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
    at
org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:699)
    at
org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:631)
    at
org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:485)
    at
org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
    at
org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
    at
org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
    at
org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:539)
    at
org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:237)
    at
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
    at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
    at
org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1061)
    at
org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:671)
    at
org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:270)
    at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at
org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at
org.apache.catalina.core.StandardContext.reload(StandardContext.java:3920)
    at
org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:426)
    at
org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345)
    at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
    at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
    at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
    at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
    at java.lang.Thread.run(Thread.java:722)

Oct 15, 2012 12:34:54 AM org.apache.catalina.core.NamingContextListener
addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: Data
source rejected establishment of connection,  message from server: "Too
many connections"
SessionListener - contextInitialized :
org.apache.catalina.core.ApplicationContextFacade@457605b1
Oct 15, 2012 12:34:54 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/ted2012] is completed



Thanks for your time




On Sun, Oct 14, 2012 at 11:19 PM, Mark Eggers <its_toasted@yahoo.com> wrote:

> On 10/14/2012 12:14 PM, g. rgar wrote:
>
>> I am developing a small java ee app (java 1.7, eclipse juno, tomcat
>> 7.0.30,
>> windows 7 professional, mysql-connector-java-5.1.22-**bin.jar, vanilla
>> servlets/jsp MVC)
>>
>> All works fine - while I change things and save .java files in eclipse it
>> apparently redeploys the app on Tomcat - after some redeployments I get :
>>
>> com.mysql.jdbc.exceptions.
>> jdbc4.**MySQLNonTransientConnectionExc**eption: Data source rejected
>> establishment of connection,  message from server: "Too many connections"
>>
>> WARNING: Unexpected exception resolving reference
>> com.mysql.jdbc.exceptions.**jdbc4.**MySQLNonTransientConnectionExc**eption:
>> Data
>> source rejected establishment of connection,  message from server: "Too
>> many connections"
>>      at sun.reflect.**NativeConstructorAccessorImpl.**newInstance0(Native
>> Method)
>>      at
>> sun.reflect.**NativeConstructorAccessorImpl.**newInstance(**
>> NativeConstructorAccessorImpl.**java:57)
>>      at
>> sun.reflect.**DelegatingConstructorAccessorI**mpl.newInstance(**
>> DelegatingConstructorAccessorI**mpl.java:45)
>>      at java.lang.reflect.Constructor.**newInstance(Constructor.java:**
>> 525)
>>      at com.mysql.jdbc.Util.**handleNewInstance(Util.java:**407)
>>      at com.mysql.jdbc.Util.**getInstance(Util.java:382)
>>      at com.mysql.jdbc.SQLError.**createSQLException(SQLError.**
>> java:1013)
>>      at com.mysql.jdbc.SQLError.**createSQLException(SQLError.**java:987)
>>      at com.mysql.jdbc.SQLError.**createSQLException(SQLError.**java:982)
>>      at com.mysql.jdbc.MysqlIO.**doHandshake(MysqlIO.java:1116)
>>      at com.mysql.jdbc.ConnectionImpl.**coreConnect(ConnectionImpl.**
>> java:2338)
>>      at
>> com.mysql.jdbc.ConnectionImpl.**connectOneTryOnly(**
>> ConnectionImpl.java:2371)
>>      at com.mysql.jdbc.ConnectionImpl.**createNewIO(ConnectionImpl.**
>> java:2163)
>>      at com.mysql.jdbc.ConnectionImpl.**<init>(ConnectionImpl.java:**794)
>>      at com.mysql.jdbc.**JDBC4Connection.<init>(**
>> JDBC4Connection.java:47)
>>      at sun.reflect.**GeneratedConstructorAccessor22**
>> .newInstance(Unknown
>> Source)
>>      at
>> sun.reflect.**DelegatingConstructorAccessorI**mpl.newInstance(**
>> DelegatingConstructorAccessorI**mpl.java:45)
>>      at java.lang.reflect.Constructor.**newInstance(Constructor.java:**
>> 525)
>>      at com.mysql.jdbc.Util.**handleNewInstance(Util.java:**407)
>>      at com.mysql.jdbc.ConnectionImpl.**getInstance(ConnectionImpl.**
>> java:378)
>>      at
>> com.mysql.jdbc.**NonRegisteringDriver.connect(**
>> NonRegisteringDriver.java:305)
>>      at
>> org.apache.tomcat.jdbc.pool.**PooledConnection.**connectUsingDriver(**
>> PooledConnection.java:278)
>>      at
>> org.apache.tomcat.jdbc.pool.**PooledConnection.connect(**
>> PooledConnection.java:182)
>>      at
>> org.apache.tomcat.jdbc.pool.**ConnectionPool.**createConnection(**
>> ConnectionPool.java:699)
>>      at
>> org.apache.tomcat.jdbc.pool.**ConnectionPool.**borrowConnection(**
>> ConnectionPool.java:631)
>>      at
>> org.apache.tomcat.jdbc.pool.**ConnectionPool.init(**
>> ConnectionPool.java:485)
>>      at
>> org.apache.tomcat.jdbc.pool.**ConnectionPool.<init>(**
>> ConnectionPool.java:143)
>>      at
>> org.apache.tomcat.jdbc.pool.**DataSourceProxy.pCreatePool(**
>> DataSourceProxy.java:116)
>>      at
>> org.apache.tomcat.jdbc.pool.**DataSourceProxy.createPool(**
>> DataSourceProxy.java:103)
>>      at
>> org.apache.tomcat.jdbc.pool.**DataSourceFactory.**createDataSource(**
>> DataSourceFactory.java:539)
>>      at
>> org.apache.tomcat.jdbc.pool.**DataSourceFactory.**getObjectInstance(**
>> DataSourceFactory.java:237)
>>      at
>> org.apache.naming.factory.**ResourceFactory.**getObjectInstance(**
>> ResourceFactory.java:143)
>>      at
>> javax.naming.spi.**NamingManager.**getObjectInstance(**
>> NamingManager.java:321)
>>      at org.apache.naming.**NamingContext.lookup(**
>> NamingContext.java:843)
>>      at org.apache.naming.**NamingContext.lookup(**
>> NamingContext.java:154)
>>      at org.apache.naming.**NamingContext.lookup(**
>> NamingContext.java:831)
>>      at org.apache.naming.**NamingContext.lookup(**
>> NamingContext.java:168)
>>      at
>> org.apache.catalina.core.**NamingContextListener.**addResource(**
>> NamingContextListener.java:**1061)
>>      at
>> org.apache.catalina.core.**NamingContextListener.**createNamingContext(**
>> NamingContextListener.java:**671)
>>      at
>> org.apache.catalina.core.**NamingContextListener.**lifecycleEvent(**
>> NamingContextListener.java:**270)
>>      at
>> org.apache.catalina.util.**LifecycleSupport.**fireLifecycleEvent(**
>> LifecycleSupport.java:119)
>>      at
>> org.apache.catalina.util.**LifecycleBase.**fireLifecycleEvent(**
>> LifecycleBase.java:90)
>>      at
>> org.apache.catalina.core.**StandardContext.startInternal(**
>> StandardContext.java:5173)
>>      at org.apache.catalina.util.**LifecycleBase.start(**
>> LifecycleBase.java:150)
>>      at
>> org.apache.catalina.core.**StandardContext.reload(**
>> StandardContext.java:3920)
>>      at
>> org.apache.catalina.loader.**WebappLoader.**backgroundProcess(**
>> WebappLoader.java:426)
>>      at
>> org.apache.catalina.core.**ContainerBase.**backgroundProcess(**
>> ContainerBase.java:1345)
>>      at
>> org.apache.catalina.core.**ContainerBase$**ContainerBackgroundProcessor.*
>> *processChildren(ContainerBase.**java:1530)
>>      at
>> org.apache.catalina.core.**ContainerBase$**ContainerBackgroundProcessor.*
>> *processChildren(ContainerBase.**java:1540)
>>      at
>> org.apache.catalina.core.**ContainerBase$**ContainerBackgroundProcessor.*
>> *processChildren(ContainerBase.**java:1540)
>>      at
>> org.apache.catalina.core.**ContainerBase$**ContainerBackgroundProcessor.*
>> *run(ContainerBase.java:1519)
>>      at java.lang.Thread.run(Thread.**java:722)
>>
>>
>> I suspect the data source is not closed properly **on redeployment** - I
>> have no probs while keeping the app open. I am able to replicate the
>> behavior by just touching the files and never once open the app in the
>> browser or do anything in my app (involving DB access)
>>
>>
>> context.xml :
>> <pre>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Context antiJARLocking="true" path="/ted2012">
>>      <Resource name="jdbc/TestDB" auth="Container"
>> type="javax.sql.DataSource"
>>          maxActive="100" maxIdle="30" maxWait="10000" username="root"
>>          password="root"
>> factory="org.apache.tomcat.**jdbc.pool.DataSourceFactory"
>>          driverClassName="com.mysql.**jdbc.Driver"
>> url="jdbc:mysql://localhost:**3306/ted2012?useUnicode=yes&**
>> amp;characterEncoding=UTF-8"
>>          removeAbandoned="true" removeAbandonedTimeout="60" />
>> </Context>
>> </pre>
>>
>> Pool class :
>>
>> <pre>
>> import java.sql.Connection;
>> import java.sql.ResultSet;
>> import java.sql.SQLException;
>> import java.sql.Statement;
>>
>> import javax.naming.Context;
>> import javax.naming.InitialContext;
>> import javax.sql.DataSource;
>>
>> class DBConnectionPool {
>>
>>      private DataSource ds = null;
>>
>>      private DBConnectionPool() {
>>          try {
>>              Context context = new InitialContext();
>>              Context envctx = (Context) context.lookup("java:comp/env"**
>> );
>>              ds = (DataSource) envctx.lookup("jdbc/TestDB");
>>          } catch (Exception e) {
>>              e.printStackTrace(); // TODO
>>          }
>>      }
>>
>>      private static enum PoolSingleton {
>>          POOL_INSTANCE;
>>
>>          private static final DBConnectionPool singleton = new
>> DBConnectionPool();
>>
>>          private DBConnectionPool getSingleton() {
>>              return singleton;
>>          }
>>      }
>>
>>      private static DBConnectionPool getDBConnectionPoolInstance() {
>>          return PoolSingleton.POOL_INSTANCE.**getSingleton();
>>      }
>>
>>      static Connection getConnection() {
>>          try {
>>              return getDBConnectionPoolInstance().**ds.getConnection();
>>          } catch (SQLException e) {
>>              e.printStackTrace(); // TODO
>>              return null;
>>          }
>>      }
>>
>>      static void freeConnection(Connection c) {
>>          try {
>>              c.close();
>>          } catch (SQLException e) {
>>              e.printStackTrace(); // TODO
>>          }
>>      }
>>
>>      /**
>>       * This is intended to be used in finally blocks and therefore MUST
>> NOT
>>       * THROW. See :
>> http://today.java.net/article/**2006/04/04/exception-handling-<http://today.java.net/article/2006/04/04/exception-handling->
>>       * antipatterns
>>       *
>>       * @param set
>>       * @param statement
>>       * @param conn
>>       */
>>      static void closeResources(ResultSet set, Statement statement,
>>              Connection conn) {
>>          if (set != null) {
>>              try {
>>                  set.close();
>>              } catch (SQLException e) {
>>                  e.printStackTrace(); // TODO
>>              }
>>          }
>>          if (statement != null) {
>>              try {
>>                  statement.close();
>>              } catch (SQLException e) {
>>                  e.printStackTrace(); // TODO
>>              }
>>          }
>>          if (conn != null) {
>>              try {
>>                  conn.close();
>>              } catch (SQLException e) {
>>                  e.printStackTrace(); // TODO
>>              }
>>          }
>>      }
>> }
>>
>> </pre>
>>
>> I do close connections/ results/ statement (using the closeResources - I
>> never get too many connections if I do not redeploy - let me know if it is
>> an eclipse problem
>>
>> Please get back to me if you need any more logs/traces etc
>>
>>
> My first reaction is that you're leaking connections, and that reloading
> in Eclipse exacerbates this.
>
> One thing that I notice in your code (haven't really studied it) is that
> you have no finally block. This means that if you throw any exceptions, all
> bets are off at to the state of that connection.
>
> Since you're printing the stack trace, what do the log files show? It's a
> bit of a pain to find if you're running under Eclipse - I think the log
> files exist in:
>
> workspace\.metadata\.plugins\**org.eclipse.wst.server.core\**tmp[n]\logs
>
> where [n] is an internal server number that Eclipse keeps track of.
>
> I wonder what happens when you unload your application and reload it on a
> stand-alone version of Tomcat. Check to see if you have a ClassLoader leak
> with the manager application and something like VisualVM.
>
> Finally, here's a good template for creating and destroying database
> connections:
>
> http://blog.**christopherschultz.net/index.**php/2009/03/16/properly-**
> handling-pooled-jdbc-**connections/<http://blog.christopherschultz.net/index.php/2009/03/16/properly-handling-pooled-jdbc-connections/>
>
> I use a variation of the above code as my base class, then inherit all of
> my other DAO classes from either the transaction version or the
> non-transaction version. This makes writing JDBC code pretty mindless since
> all of the boilerplate code has been taken care of by the base class.
>
> . . . . just my two cents.
> /mde/
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.**apache.org<users-unsubscribe@tomcat.apache.org>
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message