开发者

OracleConnection lifetime - best practices

开发者 https://www.devze.com 2023-01-15 11:31 出处:网络
I am using the standar开发者_开发百科d 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 thre

I am using the standar开发者_开发百科d 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.


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.


It is expensive (i.e. takes a lot of time, like 1-2 seconds) to create, so you should use a connection pool. This is a very common task that has already been solved.

0

精彩评论

暂无评论...
验证码 换一张
取 消