Folks,
I've run onto what looks like a Derby multithreading bug, but before submitting it to JIRA I thought I'd give this list a chance to comment. I did a keyword search, but it is possible that this has been reported or is commonly known. Is the EmbeddedDriver even expected to be thread safe? I've attached a short test program that displays the error for me. It creates a test database with a table, and a view onto that table. Then it creates N threads, each of which repeatedly (M times) create and drop a view onto the previously created view. Each thread has its own view name to create and drop, so they are not contending for that view. But all the created/dropped views depend on the same underlying view. When the error happens, it is a NullPointerException in org.apache.derby.iapi.sql.dictionary.TableDescriptor.getObjectName. An instance member named referencedColumnMap is checked for null at the top of the method, but later when it is dereferenced it is null, because it was set to null by another thread. I am not sure what getObjectName is used for other than error reporting. I have considered a fix of just saving the non-null reference as a method variable, to avoid the later NullPointerException. But I don't know what unintended consequences this may have. We tried synchronizing the getObjectName and the setReferencedColumnMap methods, but this tanked performance in our application. I have successfully seen the error with N=100 and M=100, on a dual-core 3GHz Pentium machine running Windows Vista Business, using JDK 1.4.2_13 and Derby trunk revision 548822. Sometimes I have to run the program several times before I see the error. I'd appreciate any insight before I officially report this as a bug. Thanks, Jeff Clary
TestEmbeddedMultiThreading.java
Description: TestEmbeddedMultiThreading.java
