TUNING DATASOURCE(JNDI API) FOR ORACLE 10gR2 IN TOMCAT 5.5.16

Discussions

J2EE patterns: TUNING DATASOURCE(JNDI API) FOR ORACLE 10gR2 IN TOMCAT 5.5.16

  1. Add to $CLASSPATH $CATALINA_HOME/common/lib/ojdbc14.jar
    Create following directory structure and tune:-
    files (./WEB-INF/web.xml & ./META-INF/context.xml) as follows bellow.
    Directory Structure of DbFs Web Application to deployed
    to TomCat 5.5.16
    [tomcat@ServerRHL Jdevdb]$ ls -CR
    .:
    DbFs.war index.html META-INF WEB-INF

    ./META-INF:
    context.xml

    ./WEB-INF:
    classes src web.xml

    ./WEB-INF/classes:
    coreservlets

    ./WEB-INF/classes/coreservlets:
    DbServlet.class

    ./WEB-INF/src:
    DbServlet.java

    ***************************
    File ./META-INF/context.xml
    ***************************
    <Context debug="0" docBase="/DbFs" path="/DbFs" reloadable="true">
    <Resource name="jdbc/oracle10g"
        auth="Container"
        type="javax.sql.DataSource"
        driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@ServerRHL.informatics.dstu.net:1522:jdevdb"
        username="hr"
        password="hr"
        maxActive="20"
        maxIdle="10"
        maxWait="-1" />
    </Context>

    **********************
    File ./WEB-INF/web.xml
    **********************
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <resource-ref>
     <description>Oracle Datasource example</description>
     <res-ref-name>jdbc/oracle10g</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
    </resource-ref>
    <servlet>
      <servlet-name>DbServlet</servlet-name>
      <servlet-class>coreservlets.DbServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>DbServlet</servlet-name>
    <url-pattern>/servlet/coreservlets.DbServlet</url-pattern>
    </servlet-mapping>

    </web-app>
    *********************************
    File ./WEB-INF/src/DbServlet.java
    *********************************
    View [1] chapter 21.3.

    Then complile:-
    [tomcat@ServerRHL src]$ javac -d /home/tomcat/Jdevdb/WEB-INF/classes DbServlet.java

    Create index.html:-

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN">
    <HTML>
    <HEAD><TITLE>Servlet Connection Pooling: A Test</TITLE></HEAD>
    <!-- Causes 25 near simultaneous requests for same servlet. -->
    <FRAMESET ROWS="*" BORDER=0 FRAMEBORDER=0 FRAMESPACING=0>
    <FRAMESET COLS="*">
    <FRAME SRC="/DbFs/servlet/coreservlets.DbServlet">
    </FRAMESET>
    </HTML>

    Then:-

    [tomcat@ServerRHL Jdevdb]$ ls -l
    total 32
    -rw-rw-r-- 1 tomcat tomcat 351 Apr 29 13:45 index.html
    drwxrwxr-x 2 tomcat tomcat 4096 Apr 29 13:23 META-INF
    drwxr-xr-x 4 tomcat tomcat 4096 Apr 29 13:31 WEB-INF

    [tomcat@ServerRHL Jdevdb]$ jar cvf DbFs.war .

    Deploy DbFs.war and run.

    References.
    1.Java Servlet and JSP Cookbook. Bruce W. Perr, O'REILLY 2004
  2. Actually,
    docBase should to be the "/path/to/sourceApp" , in particular "~tomcat/Jdevdb"
  3. Pattern?[ Go to top ]

    How is this a pattern?
  4. Which tunning did you do? making -1 for maxwait make tomcat never wait for new connection for ready that cause Exception thrown when 21 or more connection are requested.