简体   繁体   中英

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. 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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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