解决 Tomcat 服务器关闭时 Proxool NullPointerException(空指针异常)

解决 Tomcat 服务器关闭时 Proxool NullPointerException(空指针异常)

1.在整合Struts2, Spring, Hibernate, 的时候连接池用到了 Proxool ,可每次 重启或者关闭Tomcat服务的时候报异常.

2.异常信息如下:
1   Exception in thread  " Shutdown Hook "  java.lang.NullPointerException
2      at org.logicalcobwebs.proxool.HouseKeeperController.shutdown(HouseKeeperController.java: 104 )
3      at org.logicalcobwebs.proxool.ProxoolFacade.shutdown(ProxoolFacade.java: 246 )
4      at org.logicalcobwebs.proxool.ProxoolFacade.shutdown(ProxoolFacade.java: 218 )
5      at org.logicalcobwebs.proxool.ShutdownHook.run(ShutdownHook.java: 95 )
6      at java.lang.Thread.run(Thread.java: 619 )


3.解决办法:
只须要在服务器关闭之前关闭proxool就OK了.
1     org.logicalcobwebs.proxool.ProxoolFacade.shutdown();


4.代码
 1  package  alex.pfms.proxool;
 2 
 3  import  org.apache.commons.logging.Log;
 4  import  org.apache.commons.logging.LogFactory;
 5  import  org.logicalcobwebs.proxool.ProxoolFacade;
 6  import  org.logicalcobwebs.proxool.admin.servlet.AdminServlet;
 7 
 8  public   class  ProxoolAdminServlet  extends  AdminServlet {
 9      
10 
11       private   static   final   long  serialVersionUID  =   3205095536164467920L ;
12       private   static   final  Log LOG  =  LogFactory.getLog(AdminServlet. class );
13      
14      @Override
15       public   void  destroy() {
16          LOG.info( " Proxool shoutdown. );
17          ProxoolFacade.shutdown();
18           super .destroy();
19      }
20      
21  }

5.为了减少一段Servlet配置所以继承了Proxool 的 AdminServlet ,现在只要指定到 ProxoolAdminServlet类即可.
 1  <!--  proxool 连接池Admin配置  -->
 2       < servlet >
 3           < description > org.logicalcobwebs.proxool.admin.servlet.AdminServlet </ description >
 4           < servlet-name > proxoolAdmin </ servlet-name >
 5           < servlet-class > alex.pfms.proxool.ProxoolAdminServlet </ servlet-class >
 6           < load-on-startup > 1 </ load-on-startup >
 7       </ servlet >
 8       < servlet-mapping >
 9           < servlet-name > proxoolAdmin </ servlet-name >
10           < url-pattern > /proxoolAdmin.servlet </ url-pattern >
11       </ servlet-mapping >


你可能感兴趣的:(解决 Tomcat 服务器关闭时 Proxool NullPointerException(空指针异常))