Re: Exception after my program sleep for 2 hours.

Thomas Fischer <[email protected]>
Newsgroups gmane.comp.jakarta.turbine.torque.user
Message-ID <OF62205A85.406AD87B-ONC1257465.002D1FCF-C1257465.002D4EB4@seitenbau.net>
> >> I have a java program that uses Torque and it is working fine with
> >> one  exception. My program might need to sleep for 2 hours, using
> >> Thread.sleep() but  after it wake up again, torque always throws an
> >> exception when I try to call doSelect(). Is there  anyway to avoid
> >> this?.  This program don't do any  connection handling at all.
> >>
> >
> > The exception indicates that this is a mysql problem. please search the
net
> > for this mysql problem.
> >
> Well, as far as I can see, the problem is that torque reuse the same
> mysql connection for all its queries.
> This is in itself a good thing, because it would be a waste to open a
> new connection each time it perform a query,
> but when I put the application to sleep, the connection times out
> because it is not used in 2 hours.
>
> But torque don't detect that the connection is timed out, and then it
> get this mysql error, when it tries to use the timed out connection.
>
> As far as I can see there are 2 possible solutions: Either torque should
> detect that the connection is closed, and then
> open a new connection, or I should tell torque to close the connection
> before I call Thread.sleep and then tell
> torque to reopen the connection after the program wake up. But I could
> not find any api calls to do this.
>

Then the underlying connection pool is not configured to do this. See

http://db.apache.org/torque/releases/torque-3.3/runtime/reference/initialisation-configuration.html

For example, use.

torque.dsfactory.${databaseName}.pool.testOnBorrow=true
torque.dsfactory.${databaseName}.pool.validationQuery=SELECT 1

in your torque.properties.

    Thomas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.