C3p0 - UnreturnedConnectionTimeout 在被 C3p0 抛出时不会破坏流控制

C3p0 - UnreturnedConnectionTimeout does not break the flow control while being thrown by C3p0

假设我有以下代码:

try {
    //dao.querier behind the Scenes is using 
    //A Hibernate query with C3p0
    List<?> newItems = dao.querier(true);
} catch (Exception e) {
    e.printStackTrace();
} 

方法 dao.querier 的调用使用 C3p0 和 Hibernate。正在配置 属性 unreturnedConnectionTimeout:

unreturnedConnectionTimeout=300

当我确实有一个没有 return 到池的连接时,c3p0 说 - “java.lang.Exception:仅调试:过期资源签出堆栈跟踪”。

这个异常是不是被我的代码片段中的catch块捕获了。通过调试我的应用程序,答案似乎是否定的。 有什么方法可以捕获该异常吗?

不,您不可能捕捉到异常。您看到的 "Exception" 从未被抛出。它由 debugUnreturnedConnectionStackTraces 生成,然后要求转储它的堆栈跟踪,以便向您显示泄漏连接的代码路径。

unreturnedConnectionTimeout 存在于 close() 已泄漏的连接(并帮助您修复泄漏)。在任何堆栈或任何 try/catch 块中都不应再访问这些连接。如果您将 unreturnedConnectionTimeout 设置为一个太小的值,以至于在应用程序仍在使用它们时连接由于设置而关闭,当您的应用程序尝试使用连接后,您将看到普通异常已关闭。