I am using c3p0 to handle database connection pooling in a multithreaded environment. The question might pertain to other pooling libs, but this is what I have.
Recently I've needed to implement interruption handling on such threads using directly or indirectly c3p0, and have noticed that if interrupt()
is called right when c3p0Datasource.getConnection()
is trying to fetch me a Connection
from the pool, it throws an InterruptedException
.
Obviously, this happens because of the wait()
at java.lang.Object.wait(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1414)
Cool. The question is how do you handle this properly - both is case a) you want to continue with the transaction before your thread terminates, and b) you want to abort.
I've tried a solution that seems to be working fine (posted as answer) - actually, I think this subject is closed. Feel free to chip in otherwise, thanks!