tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nancy Crisostomo Martinez" <nanc...@correo.uqroo.mx>
Subject Re: [help!] Strange Tomcat's behaviour
Date Fri, 23 Aug 2002 15:39:06 GMT
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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message