• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When to release JDBC resources?

 
Enrique Castro
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody i have a question for you ranchers.

we are developing a social networking site and we are about to start with the programming phase
at the beginning we thought that using JPA was a good idea but then we chose to use pure JDBC
,we have just started to create the basic logic with JDBC, but at this point we have a dilema...

JDBC allows programmers when to close resources such as resultsets, connections, preparedstatements, etc
it can be after the transaction or whenever you want so this is the question we have, when to release these resources?...

we started to programming, we release resources after transaction is done, but at the other hand we have a different point of view...
if we leave the connection and preparedstatements remain open during session we would have a global resource
which will be closed when session is closed, but we want to be sure that we are in the right way closing after transaction,
at the beginning we thought resources will be released correctly in this was and performance is better, but right now we are not sure....

we do not know which technique to use...

is it better to close resources per transaction or having those resources available during session?

global resources make the same job without having to request many times to the server and pool..
but the issue we consider against this method is that if the client session accidentally closes then those jdbc resources remain until garbage collector
makes its job and i do not want to be depending on it, having unleashed resources that could not be closed may affect performance, however closing resources per transaction may affect performance too.

which way do you think we should apply to, i have thought about it and having a transactional application
is not easy cause you have to consider many situations, and one important fact is knowing how to manage the resources the application uses.


would like to hear some advices, thanks in advanced.
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a web application? Then use a connection pool, and don't hold on to a connection which you take from the pool longer than a single request. Definitely do not use one connection per session.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Definitely do not use one connection per session.

Quoted for emphasis!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic