简体   繁体   English

OracleConnection生命周期 - 最佳实践

[英]OracleConnection lifetime - best practices

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. 我使用标准的Oracle驱动程序连接到数据库,但我不能真正同意我的同事关于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. 我要感谢更详细的解释,哪种方式使用它是首选的,为什么。

Please correct me if I am wrong, but it seems that by default the oracle driver pools connections to the database automatically. 如果我错了,请纠正我,但似乎默认情况下oracle驱动程序自动将连接汇集到数据库。 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 is expensive (ie takes a lot of time, like 1-2 seconds) to create, so you should use a connection pool. 它是昂贵的(即需要很多时间,如1-2秒)来创建,所以你应该使用连接池。 This is a very common task that has already been solved. 这是一项已经解决的非常常见的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM