Subject | Re: [Firebird-Java] Tomcat Struts Firebird |
---|---|
Author | Rick Fincher |
Post date | 2002-12-31T00:44:14Z |
Hi John,
From the code below it doesn't look like your app is keeping the connection
open for 60-90 minutes, so Struts must be pooling the data source somewhere.
Firebird has a timout value that is set on the server. It looks like the
Firebird timeout may be expiring and Struts doesn't check to see if it is
still alive before using it. The pool is pretty brain dead if it doesn't
check for this and attempt to open a new connection.
I've seen this issue discussed on the Tomcat and Struts mail lists, so you
might want to check the archives there for solutions.
I believe this could be a problem with DBCP, the Jakarta connection pooling
code. It may have been fixed in a later version. Check DBCP.jar in your
setup and see if there is a newer version on the Jakarta web site.
It may also be that what is happening is a connection pool leak. The
connections are never released because somewhere in the code a statement,
result set, or connection is not closed. After a time, all available
connections are used up and an error is thrown.
This probably isn't the case here, but you can check the error logs to see
what method is generating the error to be sure.
If it is a leak, it may not be in your code. DBCP can also be configured to
"removeAbandoned" connections to help stop leaks.
There are several possible workarounds to the timeout problem:
Set the timeout value on the Firebird server to a larger value.
Set up a servlet that makes a low overhead call to Firebird every 45 minutes
(ugly but it works).
Instead of FBDriver use FBWrappingDataSource and call
setIdleTimeOutMinutes(long idleTimoutMilliseconds) to crank up the timeout
value. You should be able to use <set-property property="IdleTimeOutMinutes"
value="10000000"/>
This returns a data source instead of a driver so you will have to modify
your setup accordingly.
You may want to see if Struts is expecting a particular error in this case
that JayBird is not returning.
I seem to remember the MySQL folks having this problem in Tomcat too.
Hope this helps,
Rick
From the code below it doesn't look like your app is keeping the connection
open for 60-90 minutes, so Struts must be pooling the data source somewhere.
Firebird has a timout value that is set on the server. It looks like the
Firebird timeout may be expiring and Struts doesn't check to see if it is
still alive before using it. The pool is pretty brain dead if it doesn't
check for this and attempt to open a new connection.
I've seen this issue discussed on the Tomcat and Struts mail lists, so you
might want to check the archives there for solutions.
I believe this could be a problem with DBCP, the Jakarta connection pooling
code. It may have been fixed in a later version. Check DBCP.jar in your
setup and see if there is a newer version on the Jakarta web site.
It may also be that what is happening is a connection pool leak. The
connections are never released because somewhere in the code a statement,
result set, or connection is not closed. After a time, all available
connections are used up and an error is thrown.
This probably isn't the case here, but you can check the error logs to see
what method is generating the error to be sure.
If it is a leak, it may not be in your code. DBCP can also be configured to
"removeAbandoned" connections to help stop leaks.
There are several possible workarounds to the timeout problem:
Set the timeout value on the Firebird server to a larger value.
Set up a servlet that makes a low overhead call to Firebird every 45 minutes
(ugly but it works).
Instead of FBDriver use FBWrappingDataSource and call
setIdleTimeOutMinutes(long idleTimoutMilliseconds) to crank up the timeout
value. You should be able to use <set-property property="IdleTimeOutMinutes"
value="10000000"/>
This returns a data source instead of a driver so you will have to modify
your setup accordingly.
You may want to see if Struts is expecting a particular error in this case
that JayBird is not returning.
I seem to remember the MySQL folks having this problem in Tomcat too.
Hope this helps,
Rick
----- Original Message -----
> Hello -
> I am using the RC2 driver with Tomcat 4.1.18 and
> Struts 1.0.2 and Firebird 1.0.2. My test application
> is a user list where you login and add, edit, and
> delete users. Everything in my test application works
> initially, however after 60 to 90 minutes of
> inactivity the database connection is dropped by
> Firebird and then the next time the application is
> accessed database exceptions are thrown (apparently
> Struts doesn't know the connection is gone) and the
> application crashes and must be restarted. I have
> included my datasource setting and a code snippet
> below. If anyone has a suggestion, it would be
> greatly appreciated.
>
> Struts Datasource -
>
> <data-sources>
> <data-source>
> <set-property property="driverClass"
>
> value="org.firebirdsql.jdbc.FBDriver"/>
> <set-property property="url"
> value="jdbc:firebirdsql:localhost/3050:/opt/interbase/db/employee.gdb"/>
> <set-property property="user" value="SYSDBA"/>
> <set-property property="password" value="xxx"/>
> </data-source>
> </data-sources>
>
> Code from Employee Listing -
>
> ServletContext context = servlet.getServletContext();
> DataSource dataSource =
>
> (DataSource)Context.getAttribute(Action.DATA_SOURCE_KEY);
>
> try {
> conn = dataSource.getConnection();
> stmt = conn.createStatement();
> rs = stmt.executeQuery("SELECT e.*,r.*,d.* " +
> "FROM EMPLOYEE_TBL e, " +
> "ROLE_TBL r, " +
> "DEPARTMENT_TBL d WHERE " +
> "e.ROLEID = r.ROLEID AND " +
> "e.DEPID = d.DEPID;");
>
> while (rs.next()) {
>
> employee = new Employee();
>
> employee.setUsername(rs.getString("username"));
> ...
> employees.add(employee);
> }
> conn.commit();
>
> rs.close();
> stmt.close();
> conn.close();
> }
>
> TIA -
> John Croft
>
>
>