cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephan Coboos <cromo...@gmx.net>
Subject Avalon-Component and pooling
Date Mon, 02 Feb 2004 18:38:13 GMT
Hello,

in my avalon component I'am retrieving a datasource object and from that 
I'am getting a connection object. My component has several methods and 
some of them are communicating together. Like the following:

public Object methodA() {
 
   // Here connection will be used...
   return new Object();
}

public void methodB() {

   // Here connection will be used...
   this.methodA();
}

....

So how to share connections between the methods?

The first (bad) idea is to create a new Connection each time a new 
Method is started:

public void method() {

   try {
      Connection con = this.datasource.getConnection();
      ...
   } catch(SQLException ex) {
      // Do something
   } finally {
      con.close();
   }
}

Another idea is to implement the interfaces Initializable and Recyclable 
and creating in method initialize() the connection and returning it back 
to the pool in recycle(). What do you think about that?

But there is one problem: What happens if an exception occures which was 
not catched? Like a ParameterException or a NullPointer? How to return 
the connection clear back to the pool?

Is there a best practice way?

Thank you!

Regards
Stephan




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message