Q:

Tomcat JDBC shared DB resource

I have two applications running in Tomcat which share a database resource.  Site 1 hangs when there is any kind of load on site 2.  Can anyone tell me if there are any issues with declaring the shared resource as below in my server.xml file?  Or if the various 'max' parameters could be the issue? 
thanks for any help
I use JDBC, and my server.xml file is as follows;
<!--  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>

I now have my thread dumps, and they contain numerous references to my db connections.  Such as;
"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)

My SQLController class is used as a connection helper file, which looks like this;
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());
    }

}
}

I have removed the name of the db. 
Does anything appear to be out of place with this method of connection? 
thanks in advance : )

A:

Those will be treated as separate resources so they should be independent.  You need to do some digging to find out where the bottleneck is but it isn't the sharing of a connection pool because there are separate pools for site1 and site2.