You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by neuro <ne...@kart.edu.ua> on 2002/12/16 14:46:42 UTC

Torque.shutdown() does not close underlying database connections.

When using torque in my web-application I've noticed following:
Than i use tomcat\manager to reload my web-app database connections "leak".

The reason was:
Torque.shutdown() does not release any underlying database connections.

So I've dig into source and see that shutdown() does only release resources
associated with DatabaseMaps(idBroker&etc.) but doesn't release
any resources associated with DataSoucefFactorys (from dsFactoryMap
in Torque sources). Pool implementations use threads so OPEN
connections survive torque shutdown and application unloading. That's
realy unpleasent.

To solve this we can add some code to Torque.shutdown:
-------------Torque.java
    public static void shutdown()
    {
        if (dbMaps != null)
        {
           ....
        }
    //NEW CODE BEGIN
        if (dsFactoryMap != null)
        {
            Iterator factorys = dsFactoryMap.values().iterator();
            while (factorys.hasNext())
            {
                DataSourceFactory factory = (DataSourceFactory) factorys.next();
                factory.shutdown();
            }
        }
    //NEW CODE END
    }
-------------
And extend DataSourceFactory from single
    void initialize(Configuration configuration) throws TorqueException;
to
    void shutdown();
And add implementations to various implemantations :)

Since Torque relying on DBCP pools its enought to call pool.close();
to close connections.

//regards, neuro


Re: Torque.shutdown() does not close underlying database connections.

Posted by John McNally <jm...@collab.net>.
Please add to scarab.werken.com.  And patches (cvs diff -u) would be
appreciated.

john mcnally

On Mon, 2002-12-16 at 05:46, neuro wrote:
> When using torque in my web-application I've noticed following:
> Than i use tomcat\manager to reload my web-app database connections "leak".
> 
> The reason was:
> Torque.shutdown() does not release any underlying database connections.
> 
> So I've dig into source and see that shutdown() does only release resources
> associated with DatabaseMaps(idBroker&etc.) but doesn't release
> any resources associated with DataSoucefFactorys (from dsFactoryMap
> in Torque sources). Pool implementations use threads so OPEN
> connections survive torque shutdown and application unloading. That's
> realy unpleasent.
> 
> To solve this we can add some code to Torque.shutdown:
> -------------Torque.java
>     public static void shutdown()
>     {
>         if (dbMaps != null)
>         {
>            ....
>         }
>     //NEW CODE BEGIN
>         if (dsFactoryMap != null)
>         {
>             Iterator factorys = dsFactoryMap.values().iterator();
>             while (factorys.hasNext())
>             {
>                 DataSourceFactory factory = (DataSourceFactory) factorys.next();
>                 factory.shutdown();
>             }
>         }
>     //NEW CODE END
>     }
> -------------
> And extend DataSourceFactory from single
>     void initialize(Configuration configuration) throws TorqueException;
> to
>     void shutdown();
> And add implementations to various implemantations :)
> 
> Since Torque relying on DBCP pools its enought to call pool.close();
> to close connections.
> 
> //regards, neuro
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>