• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

When to release JDBC resources?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 27526
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67693
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Definitely do not use one connection per session.


Quoted for emphasis!
 
reply
    Bookmark Topic Watch Topic
  • New Topic