<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    大漠駝鈴

    置身浩瀚的沙漠,方向最為重要,希望此blog能向大漠駝鈴一樣,給我方向和指引。
    Java,Php,Shell,Python,服務器運維,大數據,SEO, 網站開發、運維,云服務技術支持,IM服務供應商, FreeSwitch搭建,技術支持等. 技術討論QQ群:428622099
    隨筆 - 238, 文章 - 3, 評論 - 117, 引用 - 0
    數據加載中……

    To prevent a memory leak, the JDBC Driver has been forcibly unregistered--有關Tomcat自動宕機的解決方案

    最近有幾個服務的Tomcat總是無緣無故的宕機,到了不得不解決的地步。
    在Stackoverflow上找到比較有用的一篇文章,解決方案如下:
    http://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered
    有以下幾個解決途徑:
    1. Ignore those warnings. Tomcat is doing its job right. The actual bug is in someone else's code (the JDBC driver in question), not in yours. Be happy that Tomcat did its job properly and wait until the JDBC driver vendor get it fixed so that you can upgrade the driver. On the other hand, you aren't supposed to drop a JDBC driver in webapp's /WEB-INF/lib, but only in server's /lib. If you still keep it in webapp's /WEB-INF/lib, then you should manually register and deregister it using a ServletContextListener.
      忽略警告。把WEB-INF/lib下的mysql驅動文件拷貝到Tomcat/lib下。如果仍然要放在WEB-INF/lib下,需要使用監聽器手動的注冊和注銷。
      下面的文章介紹如何寫監聽器,http://javabeat.net/servletcontextlistener-example/, 當然如果是Servlet3.0, 使用注解方式設置監聽也是可以的。
      下面的代碼是如何注銷。

      Step 1: Register a Listener
      web.xml
      <listener>
          
      <listener-class>com.mysite.MySpecialListener</listener-class>
      </listener>
      Step 
      2: Implement the Listener

      com.mysite.MySpecialListener.java

      public class MySpecialListener extends ApplicationContextListener {

          @Override
          
      public void contextInitialized(ServletContextEvent sce) {
              
      // On Application Startup, please…

              
      // Usually I'll make a singleton in here, set up my pool, etc.
          }

          @Override
          
      public void contextDestroyed(ServletContextEvent sce) {
            
      // This manually deregisters JDBC driver, which prevents Tomcat 7 from complaining about memory leaks wrto this class
              Enumeration<Driver> drivers = DriverManager.getDrivers();
              while (drivers.hasMoreElements()) {
                  Driver driver = drivers.nextElement();
                  try {
                      DriverManager.deregisterDriver(driver);
                      LOG.log(Level.INFO, String.format("deregistering jdbc driver: %s", driver));
                  } catch (SQLException e) {
                      LOG.log(Level.SEVERE, String.format("Error deregistering driver %s", driver), e);
                  }

              }
          }

      }
    2. Downgrade to Tomcat 6.0.23 or older so that you will not be bothered with those warnings. But it will silently keep leaking memory. Not sure if that's good to know after all. Those kind of memory leaks are one of the major causes behind OutOfMemoryError issues during Tomcat hotdeployments.
      把Tomcat降級到低版本(6.0.23以下),雖然不會報錯,但是還是存在內存益出的問題,這并不是一個好的解決方案。

    3. Move the JDBC driver to Tomcat's /lib folder and have a connection pooled datasource to manage the driver. Note that Tomcat's builtin DBCP does not deregister drivers properly on close. See also bug DBCP-322 which is closed as WONTFIX. You would rather like to replace DBCP by another connection pool which is doing its job better then DBCP. For exampleHikariCPBoneCP, or perhaps Tomcat JDBC Pool.
      把驅動文件移到Tomcat/lib文件夾下,不用使用DBCP,使用以下的連接池庫,HikariCP, BoneCP,或者Tomcat JDBC Pool.

    4. MAVEN項目

      If you are getting this message from a Maven built war change the scope of the JDBC driver to provided, and put a copy of it in the lib directory. Like this:<dependency>,
      對于MAVEN項目,由于Tomcat中存在mysql驅動文件(1中介紹),這樣在部署時就不會把mysql帶到打包文件里,注意是<scope>provided</scope>。

        <groupId>mysql</groupId>
        
      <artifactId>mysql-connector-java</artifactId>
        
      <version>5.1.18</version>
        
      <!-- put a copy in /usr/share/tomcat7/lib -->
        
      <scope>provided</scope>
      </dependency>
    好了,如果您遇到同樣的問題,可以和我溝通,聯系方式見頭部。

    posted on 2016-08-03 10:59 草原上的駱駝 閱讀(12601) 評論(0)  編輯  收藏 所屬分類: JAVA基礎知識 、JAVA框架

    主站蜘蛛池模板: 亚洲精品免费观看| 亚洲免费电影网站| 久久亚洲精品无码av| 国产成人精品免费视频动漫| 久久99国产亚洲高清观看首页| 噜噜噜亚洲色成人网站| 日本牲交大片免费观看| 亚洲1区2区3区精华液| 国产性生交xxxxx免费| 无码亚洲成a人在线观看| 免费一级毛片不卡在线播放| 亚洲午夜成人精品无码色欲| 1000部禁片黄的免费看| 久久亚洲精品无码aⅴ大香| 少妇太爽了在线观看免费视频| 久久久亚洲欧洲日产国码二区| 日韩内射激情视频在线播放免费| 中文字幕亚洲免费无线观看日本 | 四虎永久在线精品免费观看地址| 亚洲综合色7777情网站777| 国产h肉在线视频免费观看| 性xxxx黑人与亚洲| 日韩a级毛片免费视频| 亚洲阿v天堂在线2017免费| 日日噜噜噜噜夜夜爽亚洲精品 | 亚洲视频在线免费播放| 亚洲色一区二区三区四区| 国产人成免费视频| a级特黄毛片免费观看| 亚洲黑人嫩小videos| 久久久久免费看黄A片APP| 国产精品亚洲色图| 免费人成在线观看播放国产 | 国产偷国产偷亚洲高清在线| 亚洲欧洲日产国码一级毛片 | 日韩亚洲国产高清免费视频| 色九月亚洲综合网| 亚洲产国偷V产偷V自拍色戒| 色se01短视频永久免费| 国产精品美女免费视频观看| 亚洲国产精品第一区二区|