tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: [help!] Strange Tomcat's behaviour
Date Fri, 23 Aug 2002 15:45:31 GMT
Hi,
I'm not looking at your code.  It may be a really good or really bad connection manager, but
regardless, I recommend you try a tried and true connection pooling package that's out there
already.  You'll get the benefits of code maturity, support (at least to some extent ;)),
etc.  Try  PoolMan from SourceForget, or Jakarta commons-dbcp on the Jakarta site.  Good luck
;)

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Nancy Crisostomo Martinez [mailto:nancycm@balam2.cuc.uqroo.mx]
>Sent: Friday, August 23, 2002 11:39 AM
>To: Tomcat Users List
>Subject: Re: [help!] Strange Tomcat's behaviour
>
>Thank you,
>I'm using Oracle 8 database, and I'm not using a connection pool exactly.
>It is only a java class that provide a connection to every request and then
>it is returned to the same recipient but they never die.
>
>Here is the code: (And after all the crashes I know it doesn't work as well
>as I would like)
>
>          import java.sql.*;
>          import java.util.*;
>          import java.lang.*;
>
>          public class CL_Conexion implements Runnable {
>
>            //Declaración de las variables utilizadas por el pool de
>conexiones
>            private static String driver =
>"oracle.jdbc.driver.OracleDriver";
>            private static String url = "jdbc:oracle:thin:@url:port:loc";
>            private static String username = "user";
>            private static String password = "pass";
>            private static int maxConnections = 500;
>            private static int initialConnections = 30;
>            private static boolean waitIfBusy = true;
>            private static Stack pool = new Stack();
>            private static boolean connectionPending = false;
>
>
>            //Método constructor
>            public CL_Conexion() {
>
>            }
>
>            /**
>             * MÉTODO QUE REALIZA UNA CONEXION CON LA BASE DE DATOS
>             */
>            public static synchronized Connection conectarConBaseDeDatos()
>{
>              Connection conexion = null;
>              try{
>                 //Si existen conexiones en la pila de conexiones
>                 if (!pool.isEmpty()){
>                    //Obtención de la primer conexión de la pila
>                    conexion = (Connection) pool.pop();
>                    //Si la conexión obtenida está cerrada, solicitar otra
>conexión disponible de la pila.
>                    if (conexion.isClosed()) {
>                       conexion = CL_Conexion.conectarConBaseDeDatos();
>                    }
>                    else {
>                       //System.out.println("Obteniendo la conexion Numero:
>" + pool.size());
>                    }
>                 }
>                 //Si la pila está vacía
>                 else {
>                    // Se crea una nueva conexión a la base de datos
>                    conexion = makeNewConnection();
>                 }
>              }
>              catch(Exception e){
>                System.out.println(e);
>              }
>              finally{
>                //Devuelve la conexión disponible
>                return conexion;
>              }
>            }
>
>
>            /**
>             * MÉTODO QUE ES ORIGINADO DESDE LA INTEFAZ RUNNABLE Y QUE
>PERMITE CREAR HILOS PARA CADA
>             * INSTANCIA DE LA CLASE.
>             */
>            public void run() {
>              try {
>                Connection connection = makeNewConnection();
>                synchronized(this) {
>                  pool.push(connection);
>                  connectionPending = false;
>                  notifyAll();
>                }
>              }
>              catch(Exception e) { // SQLException or OutOfMemory
>                System.out.println(e);
>              }
>            }
>
>
>            /**
>             * MÉTODO QUE REALIZA UNA CONEXIÓN Y ES LLAMADO PARA LA
>INICIALIZACIÓN DE LA PILA
>             */
>            private static Connection makeNewConnection(){
>              Connection connection = null;
>              try {
>                // Carga el driver de la base de datos, si es que no ha
>sido cargado
>                Class.forName(driver);
>
>                // Establece la conexión de red a la base de datos
>                connection = DriverManager.getConnection(url, username,
>password);
>                connection.setAutoCommit(false);
>              }
>              catch(Exception cnfe) {
>                System.out.println(cnfe);
>              }
>              finally{
>                //Devuelve la conexión
>                return(connection);
>              }
>            }
>
>            /**
>             * MÉTODO QUE LIBERA LA CONEXIÓN EN USO Y LA DEVUELVE A LA PILA
>DE CONEXIONES
>             */
>            public static synchronized void liberarConexion(Connection
>connection) {
>               pool.push(connection);
>              // System.out.println("Liberando la conexion Numero: " +
>(pool.size()-1));
>            }
>
>          }
>
>Finally let me remark that when this problem happened, sometimes all the
>other services(who have database connections too) worked very well, but
>this happened only sometimes.
>
>Nancy.
>
>"Shapira, Yoav" wrote:
>
>> Hi,
>>
>> >-This means, that it required to have some DataBase connections to
>> >recover the classes availables, and to register him/her in them.
>>
>> You will need to post the relevant code and configuration parameters.
>> What's the database, what version?  Are you using connection pooling,
>> and if so what implementation, what version, and how is it configured?
>> Do you have relevant logs?  Do the tomcat logs indicate any errors?
>>
>> >-But the problem happened when I tried to test it in a very formal
>> >registration day in the school. It was terrible! because the
>> application
>> >crashed almost every half hour. And it came back to work when I
>> >restarted Tomcat.
>>
>> So it failed in test or production?  If it failed like that in
>> production, I'm sorry ;(  That sucks when it happens.
>>
>> >-It suddenly stop to work,but not all the Tomcat'services, because I
>> >tried to access other jsp file (more simple) and sometimes they worked
>> >(Not all the "crashed" times).
>>
>> So tomcat stayed OK.  It's just the JSPs that connected to the database
>> that broke?
>>
>> Yoav Shapira
>> Millennium ChemInformatics
>>
>>   -----------------------------------------------------------------------
>-
>> This e-mail, including any attachments, is a confidential business
>communication, and may contain information that is confidential,
>proprietary and/or privileged.  This e-mail is intended only for the
>individual(s) to whom it is addressed, and may not be saved, copied,
>printed, disclosed or used by anyone else.  If you are not the(an) intended
>recipient, please immediately delete this e-mail from your computer system
>and notify the sender.  Thank you.
>>
>>   -----------------------------------------------------------------------
>-
>> --
>> To unsubscribe, e-mail:   <mailto:tomcat-user-
>unsubscribe@jakarta.apache.org>
>> For additional commands, e-mail: <mailto:tomcat-user-
>help@jakarta.apache.org>

Mime
View raw message