Search code examples
javajdbcderbyjavadbbonecp

Why is BoneCP causing Derby ShutdownException after instantiation?


Basically I do:

CONNECTION_POOL = new BoneCP(config);

And then right after:

CONNECTION_POOL.getConnection().createStatement("SELECT * FROM myTable");

which will sometimes (not always) throw a org.apache.derby.iapi.error.ShutdownException. I suspect there is some kind of racing condition or threading issue with BoneCP and it's instantiation, but I can't find anything anywhere. I did see something about lazy instantiation, but setting it to true or false makes no difference.

Any help would be greatly appreciated.


Solution

  • Calling Thread.interrupt will cause derby to shutdown in some cases. To quote the Derby Guide: "As a rule, do not use Thread.interrupt() calls to signal possibly waiting threads that are also accessing a database, because Derby may catch the interrupt and close the connection to the database. Use wait and notify calls instead."

    This is actually bad because some libraries will call Thread.interrupt and so on. And in some cases it's good practice depending on what you're doing. In my opinion this is a big design flaw of the database engine.

    In any case the only solution I found was that if you're going to call Thread.interrupt(), then you need to adjust the Derby source code to ignore these thread interruptions. Specifically the method noteAndClearInterrupt(...) in the class org.apache.derby.iapi.util.InterruptStatus