db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: Torque not closing database connections
Date Sat, 01 Oct 2005 13:02:11 GMT




No, Torque.shutdown() should be the inverse of Torque.init() and should be
called only once if the application stops. Among other things, it tries to
close any database pools generated by Torque.init() if possible.
I typically put it in the destroy method of the main servlet of my
application.

   Thomas

Jim Caserta <smoothie_jc@yahoo.com> schrieb am 01.10.2005 14:51:06:

> Thomas,
>
> Is using the Shutdown also recommended as follows?
>
> try
>         {
>             db = Torque.getConnection(DATABASE_NAME);
>                  }
>         finally
>         {
>             Torque.closeConnection(db);
>             Torque.shutdown() <<============
>         }
>
> Jim
>
> --- Thomas Fischer <fischer@seitenbau.net> wrote:
>
> >
> >
> >
> >
> > I do not know much about Torque 3.0. All I can say
> > about it is that I did
> > not hear any problems about this in Torque 3.1 and
> > later.
> >
> > In principal, the reasons can be the following:
> > 1) the database pool is faulty (threading issues or
> > similar). You can try
> > to check this by updating to the newest dbcp version
> > 1.2.1 and configure
> > Torque to use it.
> > 2) There is an error in Torque code somewhere.
> > Personally, this seems quite
> > improbable to me.
> > 3) You do not close the database connections
> > correctly. For example, the
> > following is not enough
> >
> > Connection connection = Torque.getConnection()
> > // do something with connection
> > connection.close();
> >
> > because if an exception is happening before you call
> > close, the connection
> > will not be closed.
> >
> > You need to do something like the following to be on
> > the safe side (I left
> > out various catch blocks in order to show the
> > principle)
> >
> > Connection connection = null;
> > try
> > {
> >   connection = Torque.getConnection();
> >   // do something with connection
> > }
> > finally
> > {
> >   if (connection != null)
> >   {
> >     connection.close();
> >     connection = null;
> >   }
> > }
> >
> > If nothing helps, you need to write a log file when
> > you open a connection
> > and when you close the connection and find out where
> > this happens. This is
> > best done by subclassing the pool you use.
> >
> >      Thomas
> >
> >
> >
> > "Sandeep Bghavatula" <sbhagavatula@comframe.com>
> > schrieb am 30.09.2005
> > 22:18:42:
> >
> > > We use torque3.0 with turbine in our web
> > application. The database
> > > is mysql. Torque does'nt seem to be closing the
> > database
> > > connections. We end up with 50-60 connections in a
> > couple of days
> > > and have to restart the tomcat instance every 3
> > days to keep mysql
> > > from throwing up and saying thats it!! In my code,
> > I do a
> > > connection.close() wherever I have a
> > Torque.getConnection(). There
> > > is nothing in the database logs. Here is my
> > torque.properties file.
> > > Please help!!!
> > >
> > > #
> >
> -------------------------------------------------------------------
> > > # $Id: Torque.properties,v 1.1 2005/08/25 17:51:16
> > jriley Exp $
> > > #
> > > # This is the configuration file for Torque.
> > > #
> > > # Note that strings containing "," (comma)
> > characters must backslash
> > > # escape the comma (i.e. '\,')
> > > #
> > > #
> >
> -------------------------------------------------------------------
> > >
> > > # NOTE NO torque. prefix on properties - this is a
> > kluge to make it
> > > also include the TR.properties
> > >
> > > torque.applicationRoot=.
> > >
> > > #
> >
> -------------------------------------------------------------------
> > > #
> > > #  L O G G I N G
> > > #
> > > #
> >
> -------------------------------------------------------------------
> > > # We use Log4J for all Torque logging and we embed
> > the log4j
> > > # properties within our application configuration.
> > > #
> >
> -------------------------------------------------------------------
> > >
> > > # THIS SEEMS TO BE IGNORED - HENCE IT IS
> > DUPLICATED IN log4j.properties
> > >
> > >
> >
> log4j.appender.org.apache.file=${applicationRoot}/logs/log
> > >
> >
> log4j.appender.org.apache.layout=org.apache.log4j.PatternLayout
> > >
> > >
> >
> log4j.appender.org.apache.layout.conversionPattern=%d
> > [%t] %-5p %c - %m%n
> > > log4j.appender.org.apache.append=false
> > >
> > > log4j.category.org.apache.torque=INFO,
> > org.apache.torque
> > >
> >
> log4j.appender.org.apache.torque=org.apache.log4j.FileAppender
> > >
> >
>
log4j.appender.org.apache.torque.file=${torque.applicationRoot}/logs/log.txt

> >
> > >
> >
> log4j.appender.org.apache.torque.layout=org.apache.log4j.PatternLayout
> > >
> >
> log4j.appender.org.apache.torque.layout.conversionPattern=%d
> > [%t] %
> > > -5p %c - %m%n
> > > log4j.appender.org.apache.torque.append=false
> > > #
> >
> -------------------------------------------------------------------
> > > #
> > > #  T O R Q U E  P R O P E R T I E S
> > > #
> > > #
> >
> -------------------------------------------------------------------
> > > # These are your database settings. Look in the
> > > # org.apache.pool.* packages for more information.
> > > #
> > > # The parameters to connect to the default
> > database.  You MUST
> > > # configure these properly.
> > > #
> >
> -------------------------------------------------------------------
> > >
> > >
> > > torque.database.default=default
> > > ###torque.database.default.adapter=hypersonic
> > > torque.database.default.adapter = mysql
> > > ### torque.database.default.adapter=oracle
> > > ### torque.database.default.adapter=mssql
> > >
> > > ##
> > > ## Using torque's old pool
> > > ##
> > > #torque.dsfactory.default.connection.driver =
> > org.hsqldb.jdbcDriver
> > > #torque.dsfactory.default.connection.url =
> > jdbc:hsqldb:${webappRoot}
> > > /WEB-INF/db/jetspeed
> > > #torque.dsfactory.default.connection.user = sa
> > > #torque.dsfactory.default.connection.password =
> > >
> > >
> >
> torque.dsfactory.default.factory=org.apache.torque.dsfactory.
> > > TorqueDataSourceFactory
> > > # The number of database connections to cache per
> > ConnectionPool
> > > instance (specified per database)
> > >
> > torque.dsfactory.default.pool.defaultMaxConnections
> > = 10
> > > torque.dsfactory.default.pool.maxExpiryTime = 3600
> > >
> > torque.dsfactory.default.pool.connectionWaitTimeout
> > = 10
> > >
> > > ### MySQL
> > > #torque.dsfactory.default.connection.driver =
> > org.gjt.mm.mysql.Driver
> > > torque.dsfactory.default.connection.driver =
> > com.mysql.jdbc.Driver
> > > torque.dsfactory.default.connection.url =
> > jdbc:mysql://localhost:3306/*****
> > > torque.dsfactory.default.connection.user = *****
> > > torque.dsfactory.default.connection.password =
> > *****
> > >
> > >
> > > # The interval (in milliseconds) between which the
> > PoolBrokerService
> === message truncated ===
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message