laogao3232 2009-02-23 15:35
浏览 308
已采纳

tomcat 数据库连接池 性能问题!

tomcat运行一段就报这个错!

2009-2-23 15:09:30 org.apache.catalina.loader.WebappClassLoader loadClass
信息: Illegal access: this web application instance has been stopped already. Could not load com.mysql.jdbc.Messages. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1249)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1209)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at com.mysql.jdbc.CommunicationsException.(CommunicationsException.java:174)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2707)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2618)
at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1337)
at com.mysql.jdbc.Connection.realClose(Connection.java:4386)
at com.mysql.jdbc.Connection.cleanup(Connection.java:1962)
at com.mysql.jdbc.Connection.finalize(Connection.java:3098)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Unknown Source)
at java.lang.ref.Finalizer.access$100(Unknown Source)
at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

不影响使用,可是可以看出来连接关闭了。这个是什么原因造成功,之间没有什么操作!这个肯定是影响性能的!
这个和数据库连接池的配置有关系吗?我没有配置连接池!!!只是有个类!

package jdbc;
import javax.sql.DataSource;

import org.apache.commons.dbcp.ConnectionFactory;
import org.apache.commons.dbcp.DriverManagerConnectionFactory;
import org.apache.commons.dbcp.PoolableConnectionFactory;
import org.apache.commons.dbcp.PoolingDataSource;
import org.apache.commons.pool.impl.GenericObjectPool;

/*******************************************************************************

  • this class read properties from connectionPool.properties and contructor is a
  • jdbc connection pool in this connection pool we use dbcp as pool implement.
  • getConnection method can used to get a jdbc connection . when you want return
  • the connection to the pool , just call Connection.close().
  • sample:
  • Connection conn = null;
  • try {
  • conn = DB2ConnectionPool.getConnection();
  • //do db operation
  • } catch (SQLException e) {
  • e.printStackTrace();
  • } finally {
  • try {
  • if (null != conn)
  • conn.close();
  • } catch (Exception e) {
  • }
  • }
  • @author zhouHongCheng
    ******************************************************************************/
    public class MySQLBConnectionPool {
    // log file

    // data source instance
    public static DataSource dataSource = null;

    static {
    try {
    dataSource = initlize();
    } catch (Exception ex) {
    String errorMsg = " MySQLConnectionPool initlize failed \n"
    + ex.getMessage();

    }
    

    }

    /***************************************************************************

    • initlize the DB2ConnectionPool.
    • (1) read Driver , ConnectionURL, UserName , Password
    • from DB2ConnectionPool.properties .
    • (2) use those properties to initized a DataSource,
    • and return it .

    • **************************************************************************/
      private static DataSource initlize() throws Exception {
      String driver = "com.mysql.jdbc.Driver";
      String connectionURL = "jdbc:mysql://localhost:3306/jkhtdymb?useUnicode=true&characterEncoding=utf-8";
      String userName = "root";
      String password = "";
      int maxActive = 30;
      int maxIdle = 20;
      int maxWait = 1000;

      // 2. loading jdbc driver

      try {
      Class.forName(driver);
      System.out.println("DB connect success" );
      } catch (ClassNotFoundException e) {
      throw e;
      }

      // 3.initlize a pooling datasource
      return setupDataSource(connectionURL, // url
      userName, // user name
      password, // password
      maxActive, // max active connection
      maxIdle, // max idle connection
      maxWait); // max wait time

    }

    /***************************************************************************

    • initlize a pooling DataSource
    • @param String
    • connectionURL - he connection url
    • @param String
    • usrName - the user name
    • @param String
    •        password - the password
      

      **************************************************************************/
      private static DataSource setupDataSource(String connectionURL,
      String usrName, String password, int maxActive, int maxIdle,
      int maxWait) {

      // First, we'll need a ObjectPool that serves as the
      // actual pool of connections.
      // We'll use a GenericObjectPool instance, although
      // any ObjectPool implementation will suffice.
      //
      GenericObjectPool connectionPool = new GenericObjectPool(null);
      connectionPool.setMaxActive(maxActive);
      connectionPool.setMaxIdle(maxIdle);
      connectionPool.setMaxWait(maxWait);

      //
      // Next, we'll create a ConnectionFactory that the
      // pool will use to create Connections.
      // We'll use the DriverManagerConnectionFactory,
      // using the connect string passed in the command line
      // arguments.
      //
      ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
      connectionURL, usrName, password);

      //
      // Now we'll create the PoolableConnectionFactory, which wraps
      // the "real" Connections created by the ConnectionFactory with
      // the classes that implement the pooling functionality.
      //
      PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
      connectionFactory, connectionPool, null, null, false, true);

      //
      // Finally, we create the PoolingDriver itself,
      // passing in the object pool we created.
      //
      PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
      return dataSource;

    }

}
然后logic里面

private static Connection con = null;
    private static DataSource ds = MySQLBConnectionPool.dataSource;

程序里就con=ds.getConnection();
然后正常close!

请帮忙指点下!
[b]问题补充:[/b]
大哥,你的这个我看过了!
已经设置称false了!

  • 写回答

1条回答 默认 最新

  • case0080 2009-02-23 18:33
    关注

    Question: What causes these frequent Tomcat catalina.log messages "INFO: Illegal access: this web application instance has been stopped already."? I do not want to disable INFO level logging, so it would be nice to stop the root of the problem. I tried disabling RSS and Lucence and they still keep coming out. The full log entry looks like this: May 8, 2005 9:34:09 PM org.apache.catalina.loader.WebappClassLoader loadClass INFO: Illegal
    access: this web application instance
    has been stopped already. Could not load org.xml.sax.helpers.XMLReaderFactory. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the
    illegal access, and has no functional impact.

    A:I found this explanation from web: It is possible that this is caused by Tomcat unsuccessfully reloading the web application. The app is unloaded, but all threads don't get shut down properly. As a result, when the threads try to run, they get clobbered by the fact that Tomcat has shut down its classloader, and an error is logged. The best fix is to turn off automatic webapp reloading for the application: in Tomcat's server.xml , find the declaration, and ensure it is set to: reloadable="false"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?