Mauricio Nu�ez wrote:
> Hi everyone:
>
> I have the following question:
>
> What is the best place to open a connection in a servlet: DoPost or Init?
> My question try to solve a problem with Oracle, where we have many (+100)
> open connections, and Tomcat is not closing the open connections, aparently
> because the method Destroy is not executed.
>
> 2 Linux Redhat 7.0, 1 with Oracle, 1 with Apache+Tomcat 3.1
>
> Thanks
>
> Att.
> Mauricio
> [...]
Hi :-) the following is just my guessing:
0
I suppose now our Servlet container is:
* non-distributed
* implements Servlet spec v2.2+
1
[a] use another class to hold this DBConnectionPool ->the name of this
calss is
outsideDBCPHoder
public class outsideDBCPHoder implements java.io.Serializable {
private static outsideDBCPHoder onlyOneInstance;
private X pool; //perhaps X is a Vector? I don't know
private outsideDBCPHoder() { //private constructor
... //construct pool
}
public static synchronized outsideDBCPHoder getOnlyOneInstance() {
if (onlyOneInstance == null) {
onlyOneInstance = new outsideDBCPHoder();
}
return onlyOneInstance;
}
public synchronized java.sql.Connection getDBConnection() {
... //return a available DBConnection from the pool
}
public synchronized void closeAllDBConnection() {
... //close All active DB Connection
}
// I am not sure if it is right to close the DBConnection here
// it is for if closeAllDBConnection() is not invoked, for
example,
// if the destroy() and/or finalize() of MyServlet are not
invoked.
protected synchronized void finalize(){
... //close All active DB Connection
}
}
[b] then in our Sevlet class, we use a static field to hold the
refrence
to that onlyOneInstance:
public class MyServlet extends HttpServlet{
private static outsideDBCPHoder
myDBCP=outsideDBCPHoder.getOnlyOneInstance();
...
_service/doGet/doPost{
...
java.sql.Connection con= myDBCP.getDBConnection();
...
}
public void destroy(){
myDBCP.closeAllDBConnection();
}
// I am not sure if it is right to invoke
//myDBCP.closeAllDBConnection() here, it is for if destroy()
//is not invoked.
protected void finalize(){
myDBCP.closeAllDBConnection();
}
}
2 outsideDBCPHoder is a *SingleTonBean* ->
* the reason for making it as a SingleTon is:
try to avoid the problem led by loading/unloading MyServlet several
times, but perhaps it is not necessary, I am not sure.
* the reason for that make outsideDBCPHoder Serializable is:
from the emails in Servlet-List, bean class will be loaded by
the same ClassLoader, I also don't know if it is nessary.
If it is wrong, please correct it, thanks in advance! :-)
Bo
Nov.15, 2000
___________________________________________________________________________
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