Dear All,
Here comes my code . I have got 2 DB hence 2 DataSoruce used. Our set up is WIN2k 1GB Ram . I tried to apply all Tuning
Settings as follows:
-Xms256m -Xms512m-Djavax.rmi.CORBA.UtilClass=com.ibm.CORBA.iiop.Util -Dcom.ibm.CORBA.iiop.noLcalCopies=true -Xnoclassgc -DinvocationCacheSize=100
my WAS version is 354 with fix pack= jdk_ptf_4.jar
jar files - efixes are added as follows
Q48877/53415/48452/46831/52336
My Pool Settings are as follows : Min -1 Max- 30 Idle Time Out- 180 sec Connection Time Out --180 sec and Orphan Time Out--60 secs . This I did after some testing results. What I got from my Testing Research is that As far as possible make sure that Pool Size is not reached to the maximum. Once it reaches the maximum it prolongs for a considerable time. Mine is a strong DB oriented WEB Pages with n number of connections are used.
And this is how we process the DB Connections.
For Conn.Pooling we are using a pure Java Bean which is in application mode of all JSP which retrieves con. objects ,fires Sql and make sure closes connection in all JSPs.
We are making sure all conn. objects gets closed in proper order (result set then statement object finally conn objects.
packagecom.tfl.db;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.sql.ConnectionPoolDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import com.ibm.ejs.dbm.jdbcext.*;
import java.util.Hashtable;
public class DbBean {
private
String dbname=null;
privatejavax.sql.DataSourcecpds2=null;
privatejavax.sql.DataSourcecpds=null;
java.sql.Connection con=null;
java.sql.Connection con2=null;
Hashtable env=null;
InitialContext ctx=null;
InitialContext ctx2=null;
public DbBean()
{
this.getConnReadyFor("afsweb");
this.getConnReadyFor("twh");
}
public void getConnReadyFor(String toMe)
{
env=new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
if(toMe!=null){this.dbname=toMe;}
if(toMe.equalsIgnoreCase("afsweb"))
{
try{
ctx=new InitialContext(env);
cpds =(javax.sql.DataSource)ctx.lookup("jdbc/tfl_afs");
ctx.close();
}catch(Exception e){System.out.println("DataSource Context failure ?? --- "+e);}
}
else
if(toMe.equalsIgnoreCase("afsweb"))
{
try{
ctx2=new InitialContext(env);
cpds2=(javax.sql.DataSource)ctx2.lookup("jdbc/tfl_twh");
//System.out.println("JNDI Look up done ");
ctx2.close();
} catch(Exception e){System.out.println("DataSource Look up failure ?? --- "+e);}
}
}
public java.sql.Connection connect_Me_To(String db)
{
this.dbname=db;
Connection con = null;
try{
if(db.equalsIgnoreCase("afsweb"))
{
try{
con= cpds.getConnection("afsweb","afsweb");
//System.out.println("DbBean.java Conn made to dbname 1 ==> "+this.dbname);
con.setAutoCommit(false);
if(con.isClosed()|| con== null)
{
con=null;
this.getConnReadyFor("afsweb");
con= cpds.getConnection("afsweb","afsweb");
//System.out.println("DbBean.java Conn made to dbname 2 ==> "+this.dbname);
}
}catch(Exception e)
{
con=null;
this.getConnReadyFor("afsweb");
con= cpds.getConnection("afsweb","afsweb");
//System.out.println("DbBean.java Conn made to dbname 3 ==> "+this.dbname);
}
}
else
if(db.equalsIgnoreCase("twh"))
{
try{
con=cpds2.getConnection("afsweb","afsweb");
con.setAutoCommit(false);
if(con.isClosed() || con==null)
{
con=null;
//System.out.println("DbBean speaks--con is closed !--TWH-1--make a new ");
this.getConnReadyFor("twh");
con= cpds2.getConnection("afsweb","afsweb");
}
}catch(Exception e)
{
con=null;
this.getConnReadyFor("twh");
con= cpds2.getConnection("afsweb","afsweb");;
}
}
}catch (Exception ex)
{
con=null;
System.out.println(" Err in Conn. making...to==> " +this.dbname+"--err--"+ex);
this.getConnReadyFor(this.dbname);
connectAgain(this.dbname);
}
//System.out.println("DbBean.java Conn made to dbname 4 ==> "+this.dbname);
return con;
}
public void closeAll(Connection con)
{
try{
//System.out.println("DbBean: Closing Connection now..." );
con.close();
}catch (Exception exception){System.out.println("DbBean: ClosAll Error ?..." );}
finally{
try{
if(con!=null){con.close();}
}catch(Exception ex){}
}
}
public void connectAgain(String dbname)
{
connect_Me_To(dbname);
}
}