[英]tomcat 7 how to keep jdbc connection alive for ever
I have a war that requires a permanent jdbc connection. 我有一场需要永久jdbc连接的战争。
I've tried this (context.xml) 我试过这个(context.xml)
maxActive="100"
maxIdle="3"
maxWait="1000"
minIdle="1"
But the connection still dies after a while. 但是一段时间后连接仍然存在。 How can i keep a jdbc connection alive 24/7?
我如何保持jdbc连接24/7活着?
thanks 谢谢
First of all: you cannot keep it alive forever 首先: 你不能永远保持活力
At some point something will fail / break. 在某些时候某些事情会失败/破裂。 Be it some network interruption, some maintenance of either your software or the database or something else.
是一些网络中断,一些软件或数据库或其他东西的维护。
So "I want one connection that I can use whenever I need, so it will never close automatically" is not likely to happen for you. 所以“我想要一个我可以随时使用的连接,所以它永远不会自动关闭”不太可能发生在你身上。
Instead by using a connection pool, you can have: "I want to be able to get a valid and working database connection at any point in time" is quite easy to get in comparison. 相反,通过使用连接池,您可以: “我希望能够在任何时间点获得有效且可正常工作的数据库连接” ,相比之下很容易获得。
Most good connection pools ( hikariCP , c3p0 , tomcat database pool, ...) support configuration options that guarantee (that is: if the database is up and the network connection works) you can get a valid connection when you need it. 大多数良好的连接池( hikariCP , c3p0 ,tomcat数据库池,...)支持保证的配置选项(即:如果数据库已启动且网络连接正常),您可以在需要时获得有效连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.