h**********c 发帖数: 4120 | 1 the question:
Sun has a jdbc pool example. I implement the interfaces.
The connections time out overnight.
It is not recommended to use auto-reconnect. why? the key point is I don't
know how to set auto-reconnect.
Or there is better solution.
Put simple,
how to check java.sql.connection valid? It is has abstract function isValid,
but how to overwrite it? if not valid, how to reconnect?
Thanks in advance. | b******y 发帖数: 9224 | 2 you could do a "ping" using sql, say, "select 1". If it throws exception,
that means the connection is dead.
It is like checking heartbeat... | h**********c 发帖数: 4120 | 3 I once google that somebody suggest using getMetadata (don't recall the
exact fucntion name).
I met the situation that a connection pass the getMetadata validation but
still throws exception when executing a statement.
The mysql server timeout connections at about ten hours, so it is very
difficult to find out where SQLException is thrown.
Very long code.
My temporary solution is when reaping the pool, if a connection idles more
than one hour remove it from the pool. So when try to get a connection from
the pool, we will not get a very old connection idled a very long time.
So to speak, if a pool is busy, the connections will not timeout. If the
pool is not busy, then empty the pool, start new connection when
getConnection is called. I have to wait till tomorrow to see it works or not.
【在 b******y 的大作中提到】 : you could do a "ping" using sql, say, "select 1". If it throws exception, : that means the connection is dead. : It is like checking heartbeat...
| b******y 发帖数: 9224 | 4
from
Yes, I read about the metadata solution too somewhere before.
Anyhow, the solution I have above using "select 1" works like a charm for us
.
【在 h**********c 的大作中提到】 : I once google that somebody suggest using getMetadata (don't recall the : exact fucntion name). : I met the situation that a connection pass the getMetadata validation but : still throws exception when executing a statement. : The mysql server timeout connections at about ten hours, so it is very : difficult to find out where SQLException is thrown. : Very long code. : My temporary solution is when reaping the pool, if a connection idles more : than one hour remove it from the pool. So when try to get a connection from : the pool, we will not get a very old connection idled a very long time.
| g*****g 发帖数: 34805 | 5 Connection pool is actually a pretty complicated topic.
If this is for work, I suggest you use a 3rd party library,
e.g. DBCP
isValid,
【在 h**********c 的大作中提到】 : the question: : Sun has a jdbc pool example. I implement the interfaces. : The connections time out overnight. : It is not recommended to use auto-reconnect. why? the key point is I don't : know how to set auto-reconnect. : Or there is better solution. : Put simple, : how to check java.sql.connection valid? It is has abstract function isValid, : but how to overwrite it? if not valid, how to reconnect? : Thanks in advance.
| b******y 发帖数: 9224 | 6
We are using DBCP.
Actually, anybody educate me why Sun Microsystem or Oracle couldn't come up
with these amazing tools?
【在 g*****g 的大作中提到】 : Connection pool is actually a pretty complicated topic. : If this is for work, I suggest you use a 3rd party library, : e.g. DBCP : : isValid,
| h**********c 发帖数: 4120 | 7 Empty the pool can solve the problem.
I quick-glanced DBCP not saw topics about time-out.Try later.
Thanks for replies! | B*****g 发帖数: 34098 | 8 No profit?
up
【在 b******y 的大作中提到】 : : We are using DBCP. : Actually, anybody educate me why Sun Microsystem or Oracle couldn't come up : with these amazing tools?
| b******y 发帖数: 9224 | 9
hmm, I guess you are right. As a company, probably no incentive to maintain
open source projects...
【在 B*****g 的大作中提到】 : No profit? : : up
| h**********c 发帖数: 4120 | 10 apache 好像有很多ibm 的人在里面zt.
【在 B*****g 的大作中提到】 : No profit? : : up
|
|