Search code examples
webspherewebsphere-libertyopen-liberty

Websphere liberty force connection back to pool


Let say some piece of code took a connection from the pool and did not return it back to the pool.

I want to know if there is any setting in liberty which will force a connection back to the pool if no activity is identified on the connection after some idle time, may be 10 seconds.

I am using liberty 8.5.5.9


Solution

  • Websphere Liberty does not have any mechanism that will force in-use connections back to the pool after a certain amount of time.

    The closest thing to this behavior would be the "transaction timeout" (default of 120s) which will timeout global transactions after the timeout is reached, and all resources in the global transaction will be cleaned up.

    However, by default WebSphere will always clean up leaked connections after the transaction scope ends (be it a Local Transaction Containment or a Global Transaction).

    For example, if I do the following in a servlet:

    Connection conn = ds.getConnection();
    // conn never closed!
    

    The connection would be automatically closed and returned to the connection pool when the servlet request ends.

    If you do a similar thing in a global transaction:

    tx.begin();
    Connection conn = ds.getConnection();
    // conn never closed!
    // tx never ended!
    

    The global transaction will be ended and resources will be rolled back.

    So as long as you don't have long-running service requests, the default cleanup behavior should give you the behavior you are looking for. If you do have long running service requests, then you may want to consider tuning the transaction timeout.