Proxool 连接池销毁问题

Proxool是常用开源连接池,最近遇到点该连接池销毁时的问题, 记录下来。

项目中使用JPA的hibernate实现, persistence.xml中hibernate配置的连接池是proxool. 遇到的问题是项目中有很多后台运行的service, 这些service在servlet 容器做shutdown操作时候会先被关闭,最后在contextDestroy方法中做clean操作。 

在调试中发现当servlet容器的JVM在接到shutdown操作时候,先清理了proxool的连接池线程prototyper, 然后才调用规范约定的contextDestroy()方法, 导致该方法中的service方法需要写一些shutdown操作的log时产生大量异常,类似于:

Attempt to refer to a unregistered pool by its alias XXX

找了很久为什么Jetty在关闭时会先清理proxool的线程,而不是等contextDestroy之后清理, 发现proxool 0.9.0的release中写到:

- Added ProxoolFacade.disableShutdownHook so that you can choose to explicitly shutdown Proxool programatically. This is useful because the order that the JVM calls shutdown hooks isn't easily controlled and you might want to shutdown Proxool *after* you've done some cleaning up yourself.

 

原来是proxool自己向JVM注册了shutdown hook, 在JVM关闭时会自动被调用, 在程序代码中显式调用ProxoolFacade.disableShutdownHook后禁止proxool 线程被JVM立即关闭后问题解决。

 

猜你喜欢

转载自zhukunrong.iteye.com/blog/1670394
今日推荐