Put your broker as a public static variable in a separate class

public class Globals{
    public static DbConnectionPool myBroker;
    private static boolean initialized=false;

    public static void initialize(){
        if ( initialized ) return;
        myBroker = new DbConnectionPool(...blah, blah..););
    }
}

In your init() in servlets call Globals.initialize()
The first servlet that starts will actually initialize it.

WARNING: Make sure that all servlets use Globals
from the same class loader -- that is if you really want
that they share the same broker. In Apache/jserv
terms (don't know about others) it means that
servlets and Globals must be in wrapper classpath, not in repositories.

Cheers

DD

----------
From:   Stuart Norton[SMTP:[EMAIL PROTECTED]]
Sent:   Thursday, February 17, 2000 03:06 PM
To:     [EMAIL PROTECTED]
Subject:        DbConnectionPool over multiple servlets

Hi,

This is my first post on the list, so I've finally come out of the woodwork!

I'm using the com.javaexchange.dbConnectionPool class (from
www.javaexchange.com) to access a database through an ODBC driver. This
works with one servlet, where I define a new instance of the class in the
init() of my servlet, but I'm confused about what happens when I use another
servlet that needs to talk to the same DbConnectionPool class.

The init() code in my second class contains the same code as the first (ie.
myBroker = new DbConnectionPool(...blah, blah..);), so I'm wondering whether
it's talking to the other instance from the first servlet, or making a new
instance.

Can anyone please help me.

Stuart Norton,
Densitron Technologies plc, UK
e: [EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to