0

我有两个应用程序在 Tomcat 中运行,它们共享一个数据库资源。当站点 2 上存在任何类型的负载时,站点 1 挂起。谁能告诉我在我的 server.xml 文件中声明共享资源是否有任何问题?或者,如果各种“最大”参数可能是问题?

谢谢你的帮助

我用的是JDBC,我的server.xml文件如下;

<!-- site 1 -->
    <Host name="siteone.co.uk" appBase="/var/www/siteone.co.uk" unpackWARs="true" autoDeploy="true">
    <Alias>www.siteone.co.uk</Alias>
            <Context path="" docBase="htdocs" debug="0" reloadable="true"  >
                <Resource name="jdbc/siteone" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="-1" username="siteone_user" password="**********" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/siteone"/>
            </Context>
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/www/siteone.co.uk/logs"  prefix="tomcat_access_" suffix=".log" pattern="common" resolveHosts="false"/>
    </Host>

<!-- site 2 -->
    <Host name="sitetwo.co.uk" appBase="/var/www/sitetwo.co.uk" unpackWARs="true" autoDeploy="true">
        <Context path="" docBase="htdocs" debug="0" reloadable="true">
            <Resource name="jdbc/sitetwo_db1" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="sitetwo_db1_user" password="**********" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/sitetwo_db1"/>
            <Resource name="jdbc/sitetwo_db2" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="sitetwo_db2_user" password="**********" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/sitetwo_db2"/>
            <Resource name="jdbc/siteone" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="siteone_user" password="**********" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/siteone"/>
        </Context>  
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/www/sitetwo.co.uk/logs"  prefix="tomcat_access_" suffix=".log" pattern="common" resolveHosts="false"/>
    </Host>

我现在有我的线程转储,它们包含对我的数据库连接的大量引用。如;

"TP-Processor30" daemon prio=10 tid=0x00007f6dd40ae000 nid=0x1ad4 in Object.wait()     [0x00007f6dd27b2000]
   java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000eeac1790> (a org.apache.commons.pool.impl.GenericObjectPool$Latch)
at java.lang.Object.wait(Object.java:502)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1104)
- locked <0x00000000eeac1790> (a org.apache.commons.pool.impl.GenericObjectPool$Latch)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:999)
at htSql.SQLController.<init>(SQLController.java:43)
at controllers.HomeControllerServlet.doGet(HomeControllerServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:636)

我的 SQLController 类用作连接帮助文件,如下所示;

import java.sql.*;
import javax.sql.*;
import javax.naming.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SQLController {

private static Log _logger = LogFactory.getLog( SQLController.class );

private static Statement statement = null;
private static Connection connection;
private ResultSet rs = null;
private static InitialContext ctx;
private static DataSource ds;

static{

    _logger.fatal("SQLController : 'static' called...");

    try{
        ctx = new InitialContext();
        ds = (DataSource) ctx.lookup("java:comp/env/jdbc/****************");
    }
    catch(Exception e){
        _logger.fatal("Error creating InitialContext...");
        _logger.fatal(e);
        _logger.fatal(e.getMessage());
    }

}

public SQLController(){

    _logger.fatal("SQLController : 'constructor' called...");

    try{

        if(ctx == null){
            _logger.fatal("No DB Context");
        }
        if(ds != null){
            connection = ds.getConnection();
            statement = connection.createStatement();
        }
    }
    catch(Exception e){
        _logger.fatal(e);
        _logger.fatal(e.getMessage());
    }

}

public void insert(String sql) throws Exception{

    statement.execute(sql);     
}

public ResultSet select(String sql) throws Exception{

 rs = statement.executeQuery(sql);
   return rs;

}

public void close(){

    try{
        if(statement != null){
            statement.close();
        }
        if(connection != null){
            connection.close();
        }
        if(rs != null){
            rs.close();
        }
    }
    catch(Exception e){
        _logger.fatal(e);
        _logger.fatal(e.getMessage());
    }

}
}

我已经删除了数据库的名称。

这种连接方法有什么不合适的地方吗?

提前致谢 : )

4

1 回答 1

0

这些将被视为单独的资源,因此它们应该是独立的。您需要进行一些挖掘以找出瓶颈在哪里,但这不是连接池的共享,因为 site1 和 site2 有单独的池。

于 2012-05-12T18:02:55.587 回答