Connection taking for ever. Persistant Connections Possible with Tomcat?

I'm connecting to a database that takes forever to connect with, once you are connected things happen rather quickly. I'd like to share one connection with every user that hits the site (there wont be that many 10-20 at most). That way I can always remain connected and it will take little time to serve requests. Does anyone know if this is possible?

[360 byte] By [ZimmerS1337a] at [2007-11-27 9:16:57]
# 1

Well i guess you must be talking about the concept of Connection Pooling...if tht is it

Yes it is possible with tomcat...

checkout the below links get a idea of how to do it.

http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

RahulSharnaa at 2007-7-12 22:07:06 > top of Java-index,Java Essentials,Java Programming...
# 2

Can i apply this to an object? The reason being is that my connection is a non standard connection for example:

Here you ready the server:

String host = "";

String domain = "agr.gc.ca";

String user = "zimmers";

String password = "";

new ServerInitializer().initializeServer(domain, user, password);

IServerConnection connection = new ServerConnection();

connection.connect(host);

IServerObjectManager som = connection.getServerObjectManager();

Here I am setting up the Sde3Workspace object, this is the object i'd like to share in a 'connection pool' or in my case it's more of a 'object pool'

IServerContext context = som.createServerContext("","");

IWorkspaceFactory pWorkspaceFactory = new IWorkspaceFactoryProxy(context.createObject("esriDataSourcesGDB.SdeWorkspaceFactory"));

PropertySet propSet = new PropertySet(context.createObject("esrisystem.PropertySet"));

propSet.setProperty("SERVER", "");

propSet.setProperty("INSTANCE", "5151");

propSet.setProperty("DATABASE", "");

propSet.setProperty("USER", "layerfile");

propSet.setProperty("PASSWORD", "");

propSet.setProperty("VERSION", "SDE.DEFAULT");

Sde3Workspace ws = new Sde3Workspace(pWorkspaceFactory.open(propSet,0));

Message was edited by:

ZimmerS1337

Message was edited by:

ZimmerS1337

ZimmerS1337a at 2007-7-12 22:07:06 > top of Java-index,Java Essentials,Java Programming...
# 3

> I'm connecting to a database that takes forever to

> connect with, once you are connected things happen

> rather quickly. I'd like to share one connection with

> every user that hits the site (there wont be that

> many 10-20 at most). That way I can always remain

> connected and it will take little time to serve

> requests. Does anyone know if this is possible?

ya you are talking about connection pooling ..In tomcat connection pooling is possible ie when the server starts immediately it creates a specefied no of connection pools with the database and is faster compared to connecting everytime and closing it..

this is the class where you can write the database queries seperately and call it from other classes...

public class Company

{

Connection conn=null;

Context initCtx=null;

Context envCtx=null;

DataSource ds=null;

public Company()

{

try

{

initCtx = new InitialContext();

envCtx = (Context) initCtx.lookup("java:comp/env");

ds = (DataSource) envCtx.lookup("jdbc/TPOMS");

conn = ds.getConnection();

}

catch(Exception e)

{

System.out.println("Exception in constructor Company() : "+e);

}

}

public void closeConnection()

{

try

{

conn.close();

}

catch(Exception e)

{

System.out.println("Exception in closeConnection() : "+e);

}

}

next you need the context.xml file in your application which will be something like this...

<?xml version="1.0" encoding="ISO-8859-1"?>

<Context docBase="OMS" path="/OMS" antiJARLocking="true">

<Resource name="jdbc/TPOMS" auth="Container"

type="javax.sql.DataSource" username="root" password="password"

driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/tpoms_dbo"

maxActive="8" maxIdle="4"/>

</Context>

now when you start your tomcat server this context.xml connects to the database making a connection pool...

hope this information is useful to you..

sabyasachi.roya at 2007-7-12 22:07:06 > top of Java-index,Java Essentials,Java Programming...