Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.


#42 Thread safety

Eric Lafortune

Thanks for a great tool. Looking at the source code, I get the impression there might still be a few small issues with thread safety. Please correct me if I'm wrong, since I'm not intimately familiar with the design or the implementation.

I've looked at the code of version 0.9.1 and the code in CVS.

-, line 184:
If another thread or even multiple threads have
incremented nextAvailableConnection right before
this statement, you might get another
IndexOutOfBoundsException (while catching this

-, line 430:
Conceivably, the value of isConnectionPoolUp()
changes inbetween testing it, first for acquiring
and then for releasing the write lock. That would
result in inconsistent states or even deadlocks.

Some even smaller issues:

- The code acquires/releases locks inside try/finally
blocks. The recommended pattern is to acquire
the lock right _before_ the try block, in case
acquiring the lock fails for whatever reason.

-, line 284:
The lock statusReadWriteLock is only ever used
for getting and acquiring a write lock. That
effectively seems the same as synchronizing
the method.