views:

26

answers:

1

I've come across some code that has a singleton which creates / reuses a static instance of the MSDAAB Database object. Is the Database object threadsafe after creation? I couldn't find anything one way or the other in the MSDAAB docs.

+1  A: 

Despite this answer, I think the formal answer is no.

The reason why I say that is that Database caches stored procedure parameters in an instance variable called parameterCache.

Items are added to the cache and the cache can also be cleared using the ClearParameterCache() method without first obtaining a lock on the parameterCache.

If ClearParameterCache() is called, then it is possible to hit situations where one thread thinks there is an item in the cache then another thread clears the cache and when the first thread goes to retrieve the item it has been removed and an exception is thrown.

The good news is that if ClearParameterCache() is never called then the worst I would expect is that initially the parameters could be be derived multiple times and added to the cache multiple times (by different threads). I haven't tested it but it looks like it should still work (although it is inefficient).

So, practically, as long as you don't call ClearParameterCache() I think you should be OK.

Tuzo