Pergunta

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.

Foi útil?

Solução 2

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

Outras dicas

An embedded Derby database is shut down using a call to getConnection with the shutdown property set true. This will shut down the database AND throw a ShutdownException. Nothing is wrong, but according to jdbc getConnection is only allowed to return a valid connection or throw an exception. And since there cannot be a valid connection to a database that has been shut down, and exception must be thrown. So the question here really is if the framework you use is supposed to catch this exception, or if you are supposed to handle it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top