If I open up a JDBC connection in my java code and forget to close it, will it remain open for ever? Or is there a default time out value that I can specify somewhere?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
In first place, you really need to fix the code to close it. No excuses.
As to the concrete question, that depends on the DB server used. It's the DB server who will timeout and reclaim it. Refer the DB server specific administration manual for defaults and how to change it. In case of for example MySQL, it's the wait_timeout
setting which defaults to 28800 seconds (8 hours).
回答2:
It depends on the specifics of the JDBC driver implementation. Some might have a timeout. Some might close when the connection object is garbage collected and finalize is called, but (1) you don't know how long after you stopped referencing the object it gets garbage collected, and (2) the finalize is not reliably called.