Issue Details (XML | Word | Printable)

Key: SPRNET-170
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Mark Pollack
Reporter: Mark Pollack
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Spring.NET

Provide thread safety of IApplicationContext/IObjectFactory when retrieving lazy-init singletons.

Created: 25/Aug/05 06:24 PM   Updated: 26/Apr/06 01:23 PM   Resolved: 23/Apr/06 07:01 PM
Component/s: Spring-NET-CORE
Affects Version/s: 1.0 RC1
Fix Version/s: 1.0.2

Time Tracking:
Not Specified


 Description  « Hide
This forum question http://forum.springframework.net/viewtopic.php?t=193 trigged some digging around the codebase to see if IApplicationContext/IObjectfactory are threadsafe - it doesn't look like they are. Use of synchronized data structrues isn't enough as I see use of a few synchronized blocks in Spring.Java, for example for marking objects as currently in creation and then adding the new object to the singleton cache. Seems like most, if not all, data structures in Spring.Java in these classes are declared as unsynchronized. A more detailed comparision with the Java code base would be useful here.

Mark Pollack added a comment - 14/Sep/05 12:42 AM
Compared Java/C# versions. Added additional lock in GetAliases(string name) in C#. Nothing looks blatently out of place in AbstractObjectFactory.

Nat added a comment - 12/Apr/06 06:32 AM
I use GetObject on IApplicationContext.GetObject to get a lazy-init singleton object from different threads. It seems that the method is not thread-safe. If I kick off two threads at the same time and get the object that takes time to initialize, one thread will get the object correctly while the other thread will get null back.

Bruno Baia added a comment - 21/Apr/06 03:27 AM
lazy-init singleton not tread-safe :
http://forum.springframework.net/viewtopic.php?t=440

Mark Pollack added a comment - 23/Apr/06 01:48 PM
Added back in synchronization code that accidentially got removed. Code is in line with Spring.Java semantics. Added test case that failed before current round of changes. Will confer with Jurgen as to why ObjectCurrentlyInCreationException will be thrown in corner cases instead of relying on singletonCache object locks to handle concurrency.