commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mario Ivankovits" <Mario.Ivankov...@ops.co.at>
Subject Re: [DBCP] Please let us start to improve the connection pool
Date Mon, 24 Mar 2003 18:57:24 GMT
1) ThreadLocal
This might not help anything, or do i oversee something?

Thread A gets a connection from the pool
Thread A loops until the abandoned connection interval is passed
The connection will be passed back to the pool.
Thread B gets a connection from the pool (the connection which was passed
back automatically by some pool mechanism)
Thread B starts a transaction
Thread A wakes up from sleep and call "commit()"
Thread B roll back transaction

Well, Thread A and B do always have their own TheadLocal and so, the Thread
do not "know", that the connection is abandoned.

2) Proxy
Your proxy looks much more interesting, but i think, it does also not
correctly handle the problem described above. The proxy do not "change" the
thread, only the connection does. For sure, i do not have much experiences
with the java "Proxy" thinggy, but why should
    if(  owner.get() == Thread.currentThread()  )
ever by "not true", the thread is still alive.
But maybe we could catch the method "passivate" and set the "connection" to
null, now the connection is really released.
I have to try this.

I my case, i can easy implement such method. We have only one central place
where we ge a connection from the pool, but i suggest this might not be
correct for all sort of application out there. Such an application then has
problems to decorate the connection instance.

At least, i do not understand why this should be more elegant, if it works
EVERY application has to read the docs, and implement this. This is like
"cut and paste" in an OO design, isnt it?

Mario

> class MySafeConnection implements InvokationHandler{
>
>   Connection connection;
>   WeakReference owner;
>
>    MySafeConnection(Connection connection){
>      this.connection = connection;
>      owner = new WeakReference( Thread.currentThread() );
>   }
>
>  Object invoke(Object obj, Method method, Object args[] ) throw Throwable{
>
>     if(  owner.get() == Thread.currentThread()   ){
>         method.invoke( connection, args );
>      }else{
>         throw new IllegalStateExeption();
>    }
>
>  }
>
>  static Connection decorate(Connection connection){
>
>     return
> (Connection)Proxy.newProxyInstance(connection.getClass().getClassLoader(),
>                                     new Class[] {Connection.class}, new
> MySafeConnection(connection));
>
>   }
>
> }


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message