I’m new to the list, and this is my first post. 


We found an interesting error during load testing today, and believe we have tracked it down to the Configuration class.  The bug manifested itself intermittently in a heavily loaded system. 


The Configuration class has a copy() method, and a copyTo() method.  Inside the copyTo() method, the sourceParserPool is being copied.  Note that sourceParserPool is marked as “transient,” so it’s really not supposed to be part of a copy. 


ArrayLists are not thread-safe unless protected by synchronization.  sourceParserPool is an ArrayList, and normally, it is protected by the synchronized sections in Configuration.  However, when you copy() or copyTo() the object, the you get a single instance of sourceParserPool copied to two instances of Configuration.  So in this case, the synchronization in Configuration is not protecting sourceParserPool at all. 


There are a number of transient variables in Configuration, and at least some of them are being copied by copyTo() without deep cloning.  So it looks to me like the use of copyTo() in a threaded application can be the source of numerous threading bugs.    



We fixed the bug by avoiding copyTo().  Either using a singleton Configuration instance, or creating a new Configuration on each use, appears to make the system stable again immediately.