c3p0 icon indicating copy to clipboard operation
c3p0 copied to clipboard

Resource pool not waiting on destroyer threads

Open bgedik opened this issue 9 years ago • 2 comments

In BasicResourcePool.close() destroyer threads are created, but they are never joined. This causes Tomcat to complain that there are leaking threads. Yes, they will eventually stop running, but close() should join them, so that we don't get the false alarm from Tomcat.

for (Iterator ii = cleanupResources.iterator(); ii.hasNext();) 
            addToFormerResources( ii.next() );
            managed.keySet().removeAll( cleanupResources );
            unused.removeAll( cleanupResources );
            Thread resourceDestroyer = new Thread("Resource Destroyer in BasicResourcePool.close()")
            {
                public void run()
                {
                    for (Iterator ii = cleanupResources.iterator(); ii.hasNext();)
                    {
                        try
                        {
                            Object resc = ii.next();
                            destroyResource( resc, true );
                        }
                        catch (Exception e)
                        {
                            if (Debug.DEBUG) 
                            {
                                if ( logger.isLoggable( MLevel.FINE ) )
                                    logger.log( MLevel.FINE, "BasicResourcePool -- A resource couldn't be cleaned up on close()", e );
                            }
                        }
                    }
                }
            };
            resourceDestroyer.start();
            for (Iterator ii = acquireWaiters.iterator(); ii.hasNext(); )
                ((Thread) ii.next()).interrupt();
            for (Iterator ii = otherWaiters.iterator(); ii.hasNext(); )
                ((Thread) ii.next()).interrupt();
            if (factory != null)
                factory.markBroken( this );
        }

bgedik avatar Sep 15 '16 11:09 bgedik

I also have same issue. Is it c3p0 or maybe I miss some configuration?! my c3p0 DataSource is created by Spring and has destroy-method="close".

yasserzamani avatar Feb 28 '17 10:02 yasserzamani

@yasserzamani it's no misconfiguration. @bgedik has diagnosed the issue correctly. c3p0's philosophy is to do as much as it can asynchronously, and that is true of closing ancillary resources associated with DataSources as well. in c3p0-0.9.6, i may try to offer a means of synchronous close (but no promises). for now, resources do get cleaned up, but you may need to tolerate hot-restart false alarms.

swaldman avatar Mar 06 '17 10:03 swaldman