Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > release pooled connectoin-Pass by value or reference.

Reply
Thread Tools

release pooled connectoin-Pass by value or reference.

 
 
quickcur@yahoo.com
Guest
Posts: n/a
 
      07-23-2005
I think this is a classic java question: Pass by
reference or by value. I have a DatabaseManager class
which takes care of getting conection from connection pool
and releasing the connectoin. I am not sure about the
release part. Here is my code:

class MyMainClass{

public static final void main(String[] args){

Connection connection =
DatabaseManager.getConnection();

....//jdbc work.

DatabaseManager.closeConnection(connection);
....
}


public class DatabaseManager {

public static Connection getConnection(){
Connection connection =
getConectionFromDataSource();

return connection;
}

public static void closeConnection(Connection
conn){
if (conn != null){
try{
conn.close();
}catch(SQLException sqle){
sqle.printStackTrace();
}
}
conn = null;
}}


I am not sure if the connection is released....


Thanks,

 
Reply With Quote
 
 
 
 
Raymond DeCampo
Guest
Posts: n/a
 
      07-24-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I think this is a classic java question: Pass by
> reference or by value.


I don't see what this supposed dilemma has to due with the rest of your
post.

> I have a DatabaseManager class
> which takes care of getting conection from connection pool
> and releasing the connectoin. I am not sure about the
> release part. Here is my code:
>
> class MyMainClass{
>
> public static final void main(String[] args){
>
> Connection connection =
> DatabaseManager.getConnection();
>
> ....//jdbc work.
>
> DatabaseManager.closeConnection(connection);
> ...
> }


The call to DatabaseManager.closeConnection() should be in a finally
block, unless you like tormenting your DBAs.

>
>
> public class DatabaseManager {
>
> public static Connection getConnection(){
> Connection connection =
> getConectionFromDataSource();
>
> return connection;
> }
>
> public static void closeConnection(Connection
> conn){
> if (conn != null){
> try{
> conn.close();
> }catch(SQLException sqle){
> sqle.printStackTrace();
> }
> }
> conn = null;
> }}
>
>
> I am not sure if the connection is released....


Most connection pools work by wrapping the actual Connection
implementation with their own implementation. The pool's implementation
of Connection.close() will usually return the connection to the pool.
Refer to the documentation of your specific connection pool.

>
>
> Thanks,
>


HTH,
Ray
--
XML is the programmer's duct tape.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pooled connection myth David McDivitt Java 42 03-18-2005 09:26 PM
# of pooled connections seem too high Bob ASP .Net 2 02-01-2005 07:40 PM
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. Guoqi Zheng ASP .Net 4 06-03-2004 06:39 PM
all pooled connections were in use dotNET Developer ASP .Net 2 02-24-2004 08:01 PM
Old (pooled) ASP pages makes dllhost.exe to hang after inst. .Net 1.1 Dag Sunde ASP .Net 0 12-03-2003 02:52 PM



Advertisments