|
When using the Hibernate internal connection pool in a simple Java console app, the JVM hangs and waits forever for a thread. The thread is the connection pool thread spawned in DriverManagerConnectionProviderImpl. This thread should be cleaned up by DriverManagerConnectionProviderImpl.stop(), but this method is never called in AbstractServiceRegistryImpl.destroy() (during SessionFactoryImpl.close()), or elsewhere. The only way to get the app to exit normally (yes, other than using a proper connection pool), is to do some ugly forcing like this in HibernateUtil:
public static void stopConnectionProvider() { final SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory; ConnectionProvider connectionProvider = sessionFactoryImplementor.getConnectionProvider(); if (Stoppable.class.isInstance(connectionProvider)) { ((Stoppable) connectionProvider).stop(); }
}
This bug started happening after upgrading to Hibernate 4.3.0-SNAPSHOT from 4.2.0.CR2, so it must have been introduced by a recent change.
Related stackoverflow question: http://stackoverflow.com/questions/20976322/close-sessionfactory-in-hibernate-4-3
|