OracleConnection生命周期-最佳实践 [英] OracleConnection lifetime - best practices

查看:121
本文介绍了OracleConnection生命周期-最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用标准的Oracle驱动程序来连接数据库,但是在OracleConnection的使用期限上,我并不能与同事真正达成一致.创建起来昂贵吗?它是线程安全的吗?我可以在请求之间重用它,还是应该为每个请求创建一个新请求?

I am using the standard Oracle driver to connect to the database, but I can't really agree with my colleagues on the lifespan of OracleConnection. Is it expensive to create? Is it thread safe? Can I reuse it between request, or should I create a new one for every request?

我希望能得到更详细的解释,以便更好地选择使用它的方式以及原因.

I would be grateful for a bit more detailed explanation which way of using it is preferred and why.

推荐答案

如果我错了,请纠正我,但默认情况下,似乎oracle驱动程序自动将池连接到数据库.因此,这里的最佳实践似乎是在每个请求之前创建一个新的OracleConnection对象,然后在其后进行处理-如果有可用,它将从连接池中获取,否则将创建该对象.

Please correct me if I am wrong, but it seems that by default the oracle driver pools connections to the database automatically. So the best practise here seems to create a new OracleConnection object before every request and dispose it after - it will be taken from the connection pool if available or created otherwise.

这篇关于OracleConnection生命周期-最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆