You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matthias Bauer <Ma...@livinglogic.de> on 2001/03/16 12:15:27 UTC

Re: datasource - connection timeout

Here is the change in class GenericDataSource: I am just checking whether the
connection has been closed by the database server. And if it has, then I obtain
a new connection. 

For this to work, you have to make sure that your jdbc driver is returning the
correct value for the isClosed() method. Please try to ensure this first. I am
saying this, because the Interbase jdbc driver Interclient 1.6 did not work,
PostgreSQL driver did not work, we had to patch it, only MySQL driver worked ok.

I also attached the complete file GenericDataSource.java.

Maybe you can let me know if it worked for you.

Good luck,

--- Matthias


Matthias Bauer +++ mba@livinglogic.de +++ LivingLogic AG +++ www.livinglogic.de

> 
>     /**
>      * Attempt to establish a database connection.
>      *
>      * @exception SQLException if a database access error occurs
>      */
>     public Connection getConnection() throws SQLException {
> 
>         int seconds = 0;
> 
>         // Validate the opened status of this data source
>         if (closed)
>             throw new SQLException("getConnection:  Data source is closed");
>         if (driver == null)
>             open();
> 
>         while (true) {
> 
>             // Have we timed out yet?
>             if ((loginTimeout > 0) && (seconds >= loginTimeout))
>                 break;
> 
>             // Return an existing connection from the pool if there is one
>             synchronized (connections) {
>                 if (!connections.isEmpty()) {
>                     useCount++;
>                     GenericConnection connection = (GenericConnection) connections.removeFirst();
> 
>                     // Create a new connection if the connection has been closed due to timeout or server restart
>                     if (connection.conn.isClosed())
>                     {
>                         connection = new GenericConnection
>                             (this, driver.connect(url, properties), autoCommit, readOnly);
>                     }
>                     // unclose the connection's wrapper
>                     connection.setClosed(false);
>                     return(connection);
> 
>                     // return ((Connection) connections.removeFirst()); DEBUG
>                 }
>             }
> 
>             // Create a new connection if we are not yet at the maximum
>             if (activeCount < maxCount) {
>                 Connection conn = createConnection();
>                 useCount++;
>                 return (conn);
>             }
> 
>             // Wait for an existing connection to be returned
>             try {
>                 Thread.sleep(1000);
>                 seconds++;
>             } catch (InterruptedException e) {
>                 ;
>             }
> 
>         }
> 
>         // We have timed out awaiting an available connection
>         throw new SQLException
>             ("getConnection: Timeout awaiting connection");
> 
>     }
> 



Kartik Sudarsan wrote:
> 
> hi,
>         i saw your posted message about having patched the connection timeout bug.
> please send me the patch too as i am facing the same problem while using
> datasource
> 
> Regards,
> 
> Kartik Sudarsan
> 
> IT Cube India Pvt. Ltd,
> Unit 1, 8th Floor,
> Innovator Building
> ITPL, Whitefield Road
> Ph:98450 74666
> 
> Quality is a mindset,not an event

RE: datasource - connection timeout

Posted by Kartik Sudarsan <ka...@itcube.net>.
hi,
	thanks for replying at such short notice.i compiled the java file and
replaced the class file in the struts jar. but it doesnt seem to work for
the oracle jdbc driver. if you any solutions for this, please do let me
know.

thanks,
Kartik

-----Original Message-----
From: hias@livinglogic.de [mailto:hias@livinglogic.de]On Behalf Of
Matthias Bauer
Sent: Friday, March 16, 2001 4:45 PM
To: Kartik Sudarsan
Cc: struts-user@jakarta.apache.org
Subject: Re: datasource - connection timeout


Here is the change in class GenericDataSource: I am just checking whether
the
connection has been closed by the database server. And if it has, then I
obtain
a new connection.

For this to work, you have to make sure that your jdbc driver is returning
the
correct value for the isClosed() method. Please try to ensure this first. I
am
saying this, because the Interbase jdbc driver Interclient 1.6 did not work,
PostgreSQL driver did not work, we had to patch it, only MySQL driver worked
ok.

I also attached the complete file GenericDataSource.java.

Maybe you can let me know if it worked for you.

Good luck,

--- Matthias


Matthias Bauer +++ mba@livinglogic.de +++ LivingLogic AG +++
www.livinglogic.de

>
>     /**
>      * Attempt to establish a database connection.
>      *
>      * @exception SQLException if a database access error occurs
>      */
>     public Connection getConnection() throws SQLException {
>
>         int seconds = 0;
>
>         // Validate the opened status of this data source
>         if (closed)
>             throw new SQLException("getConnection:  Data source is
closed");
>         if (driver == null)
>             open();
>
>         while (true) {
>
>             // Have we timed out yet?
>             if ((loginTimeout > 0) && (seconds >= loginTimeout))
>                 break;
>
>             // Return an existing connection from the pool if there is one
>             synchronized (connections) {
>                 if (!connections.isEmpty()) {
>                     useCount++;
>                     GenericConnection connection = (GenericConnection)
connections.removeFirst();
>
>                     // Create a new connection if the connection has been
closed due to timeout or server restart
>                     if (connection.conn.isClosed())
>                     {
>                         connection = new GenericConnection
>                             (this, driver.connect(url, properties),
autoCommit, readOnly);
>                     }
>                     // unclose the connection's wrapper
>                     connection.setClosed(false);
>                     return(connection);
>
>                     // return ((Connection) connections.removeFirst());
DEBUG
>                 }
>             }
>
>             // Create a new connection if we are not yet at the maximum
>             if (activeCount < maxCount) {
>                 Connection conn = createConnection();
>                 useCount++;
>                 return (conn);
>             }
>
>             // Wait for an existing connection to be returned
>             try {
>                 Thread.sleep(1000);
>                 seconds++;
>             } catch (InterruptedException e) {
>                 ;
>             }
>
>         }
>
>         // We have timed out awaiting an available connection
>         throw new SQLException
>             ("getConnection: Timeout awaiting connection");
>
>     }
>



Kartik Sudarsan wrote:
>
> hi,
>         i saw your posted message about having patched the connection
timeout bug.
> please send me the patch too as i am facing the same problem while using
> datasource
>
> Regards,
>
> Kartik Sudarsan
>
> IT Cube India Pvt. Ltd,
> Unit 1, 8th Floor,
> Innovator Building
> ITPL, Whitefield Road
> Ph:98450 74666
>
> Quality is a mindset,not an event