刷新 JDBC 连接池
有谁知道刷新 JDBC 连接池的最佳(或任何)方法? 我在文档中找不到任何明显的内容。 看来连接池永远不会被删除。
我当前的想法是从存储它们的哈希中删除所有数据源,这将触发我们的代码创建新数据源。 但是,我的第一次尝试抛出了 ConcurrentModificationException。
Does anyone know the best (or any) way to flush a JDBC connection pool? I can't find anything obvious in the documentation. It appears connection pools aren't meant to ever be deleted.
My current thought is to delete all DataSources from the hash we store them in, which will trigger our code to make new ones. However, my first attempt throws a ConcurrentModificationException.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不应该编写连接池。 这是由 Java EE 应用服务器处理的。
You shouldn't be writing a connection pool. That's handled by the Java EE app server.
您不应该编写连接池。 即使您想自己管理池(而不是让容器来管理),您也应该使用库(例如 Commons DBCP)。
如果你想删除哈希中的所有内容,你应该使用 hash.clear()。
如果想避免ConcurrentModificationException,则需要添加同步。
如果您删除对连接的引用(您确定您指的是数据源吗?),请务必先 close() 它们。
You shouldn't be writing a connection pool. Even if you want to manage the pool yourself (as opposed to letting a container do it), you should use a library for that (such as Commons DBCP).
If you want to delete everything from a hash, you should use hash.clear().
If you want to avoid ConcurrentModificationException, you need to add synchronization.
If you delete references to Connections (are you sure you meant DataSources?), be sure to close() them first.
为什么要删除,而不是首先创建它。
它应该基于您的应用程序服务器,也许一些 JNDI 编程可以解决这个问题。
Why do you want to delete, rather don't create it at first place.
It should be based on your appserver, may be some JNDI programming could do the trick.