MySQL connection problems on Tomcat

This is a discussion on MySQL connection problems on Tomcat within the JDBC JAVA forums in Framework and Interface Programming category; My web start application connects to a MySQL database through a servlet. The servlet accesses the database through a MySQL connector instance and returns the results the client if necessary. Everything is done through a Tomcat Linux web server. My problems seem to occur when I run the program through the servlet for the first time after a while, like the first time of the day or after not testing it on the server for some days. It can't fetch anything from the database, so the client just gets null objects back. Ultimately, a NullPointerException kills the application as it ...

Go Back   Application Development Forum > Framework and Interface Programming > JDBC JAVA

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 06-20-2008, 02:04 PM
Hakan
Guest
 
Default MySQL connection problems on Tomcat


My web start application connects to a MySQL database through a
servlet. The servlet accesses the database through a MySQL connector
instance and returns the results the client if necessary. Everything is
done through a Tomcat Linux web server.

My problems seem to occur when I run the program through the servlet
for the first time after a while, like the first time of the day or
after not testing it on the server for some days. It can't fetch
anything from the database, so the client just gets null objects back.
Ultimately, a NullPointerException kills the application as it has
nothing to work with.

The solution is very simple. I shut down Tomcat and restart it, after
which it again reads results from the database as it should. This is
just not a sustainable way to deal with it.

My employer wants to deploy it such that many different users will have
an interest in accessing it from various places and not just people with
system administrator privileges. Hence, crashes are liable to make them
spurn the application. That would make quite a lot of work useless.

Do you know the source of the mentioned problem?

Regards.

--
Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet
Die Signatur läßt sich nach Belieben anpassen ;-)
Reply With Quote
  #2  
Old 06-20-2008, 07:16 PM
Arne Vajhøj
Guest
 
Default Re: MySQL connection problems on Tomcat

Hakan wrote:
> My web start application connects to a MySQL database through a servlet.
> The servlet accesses the database through a MySQL connector instance and
> returns the results the client if necessary. Everything is done through
> a Tomcat Linux web server.
>
> My problems seem to occur when I run the program through the servlet for
> the first time after a while, like the first time of the day or after
> not testing it on the server for some days. It can't fetch anything from
> the database, so the client just gets null objects back. Ultimately, a
> NullPointerException kills the application as it has nothing to work with.
>
> The solution is very simple. I shut down Tomcat and restart it, after
> which it again reads results from the database as it should. This is
> just not a sustainable way to deal with it.
>
> My employer wants to deploy it such that many different users will have
> an interest in accessing it from various places and not just people with
> system administrator privileges. Hence, crashes are liable to make them
> spurn the application. That would make quite a lot of work useless.
>
> Do you know the source of the mentioned problem?


The most likely cause is a bug in your code related to
some state being kept between invocations.

Arne
Reply With Quote
  #3  
Old 06-20-2008, 09:18 PM
joeNOSPAM@BEA.com
Guest
 
Default Re: MySQL connection problems on Tomcat

On Jun 20, 11:04 am, Hakan <H...@softhome.net> wrote:
> My web start application connects to a MySQL database through a
> servlet. The servlet accesses the database through a MySQL connector
> instance and returns the results the client if necessary. Everything is
> done through a Tomcat Linux web server.
>
> My problems seem to occur when I run the program through the servlet
> for the first time after a while, like the first time of the day or
> after not testing it on the server for some days. It can't fetch
> anything from the database, so the client just gets null objects back.
> Ultimately, a NullPointerException kills the application as it has
> nothing to work with.
>
> The solution is very simple. I shut down Tomcat and restart it, after
> which it again reads results from the database as it should. This is
> just not a sustainable way to deal with it.
>
> My employer wants to deploy it such that many different users will have
> an interest in accessing it from various places and not just people with
> system administrator privileges. Hence, crashes are liable to make them
> spurn the application. That would make quite a lot of work useless.
>
> Do you know the source of the mentioned problem?
>
> Regards.
>
> --
> Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet
> Die Signatur läßt sich nach Belieben anpassen ;-)


I'm guessing the 'connector' has a simple JDBC connection underneath,
which is killed after a time of idleness, perhaps by a firewall or
a DBMS setting for idle sessions. One simple hack would be to store
each successful time-of-use in the servlet, and at each invoke,
compare the current time to the last successful use, and if it
hasn't been used for an hour (experiment to find the right value)
you must re-create connector. I'd see about the DBMS parameters
that might be killing the connection out from under you.
HTH,
Joe Weinstein at Oracle
Reply With Quote
  #4  
Old 06-21-2008, 05:13 AM
Hakan
Guest
 
Default Re: MySQL connection problems on Tomcat

joeNOSPAM@BEA.com wrote:


> I'm guessing the 'connector' has a simple JDBC connection underneath,
> which is killed after a time of idleness, perhaps by a firewall or
> a DBMS setting for idle sessions. One simple hack would be to store
> each successful time-of-use in the servlet, and at each invoke,
> compare the current time to the last successful use, and if it
> hasn't been used for an hour (experiment to find the right value)
> you must re-create connector. I'd see about the DBMS parameters
> that might be killing the connection out from under you.
> HTH,
> Joe Weinstein at Oracle


You are right that I had missed to close the MySQL driver connection. I
have now added close statements whenever I exit the application in the
code and a shutdown hook closing the database driver connection on
unvoluntary shutdowns. Thank you for your help.

--
Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet
Die Signatur läßt sich nach Belieben anpassen ;-)
Reply With Quote
  #5  
Old 06-21-2008, 05:40 AM
David Harper
Guest
 
Default Re: MySQL connection problems on Tomcat

Hakan wrote:
>
> My web start application connects to a MySQL database through a servlet.
> The servlet accesses the database through a MySQL connector instance and
> returns the results the client if necessary. Everything is done through
> a Tomcat Linux web server.
>
> My problems seem to occur when I run the program through the servlet for
> the first time after a while, like the first time of the day or after
> not testing it on the server for some days. It can't fetch anything from
> the database, so the client just gets null objects back. Ultimately, a
> NullPointerException kills the application as it has nothing to work with.
>
> The solution is very simple. I shut down Tomcat and restart it, after
> which it again reads results from the database as it should. This is
> just not a sustainable way to deal with it.
>
> My employer wants to deploy it such that many different users will have
> an interest in accessing it from various places and not just people with
> system administrator privileges. Hence, crashes are liable to make them
> spurn the application. That would make quite a lot of work useless.
>
> Do you know the source of the mentioned problem?
>
> Regards.


The MySQL server has a system variable named wait_timeout:

http://dev.mysql.com/doc/refman/5.0/...d_wait_timeout

If there is no activity on a TCP/IP connection for more than
wait_timeout seconds, then the server will close the connection.

The default value is 28800 seconds, or 8 hours.

You can either override the timeout globally in your server
configuration file by adding a line such as

wait_timeout = 864000

to change the timeout to 10 days for all connections, or set it on a
per-connection basis by sending the command

set wait_timeout = 864000;

to the server from each new connection.

David Harper
Cambridge, England
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:39 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.