Grzenio
Grzenio

Reputation: 36689

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.

Upvotes: 4

Views: 1849

Answers (2)

Grzenio
Grzenio

Reputation: 36689

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.

Upvotes: 4

Erich Kitzmueller
Erich Kitzmueller

Reputation: 36987

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.

Upvotes: 1

Related Questions