PDA

View Full Version : Threads


Tolo
08-24-2005, 10:51 PM
Hi

I’m testing Spring.Net and I am really impressed about your work, congratulations :D

I wish to use Spring.Net in an application where I will need to use it from different threads. Can you tell me if Spring.Net is thread safe (especially the classes who implement IApplicationContext and IObjectFactoy)? Any recommendations to use it in a multi thread application?

Thanks

Mark Pollack
08-26-2005, 12:30 AM
Hi,

The answer should be yes - as that is what is claimed at least for the Java version based on this post (http://forum.springframework.org/viewtopic.php?t=2312&highlight=thread+safe), but I'm unaware of any tests that particularly address this issue. A quick walk through the code shows that those classes in Spring.NET are most likely not thread safe and I see some differences with the latest Spring.Java code (though I should compare w/ 1.2.2)

I've made a JIRA issue (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-170) to investigate and get back to you. What is your usage scenario? I guess you want to share the service locator singleton ContextRegistry (http://www.springframework.net/doc/reference/html/objects.html#objects-servicelocator) from multiple threads?

By the way, while we are on the topic of threads, you maybe interested in checking out the concurrency utilities in Spring.Threading. You can find some docs on the web (http://www.springframework.net/doc/reference/html/threading.html) and the code is in the interium release on the download page (http://www.springframework.net/download.html). There are more utilities in the codebase than currently doc'd.

Cheers,
Mark

Tolo
08-26-2005, 09:01 AM
Hi,

I’m not using the service locator singleton ContextRegistry from multiple threads, but I’m using a similar approach. I’m using a “global/static” object to my assembly who hold an IObjectFactory (among other objects) and I share that object. I was unaware about ContextRegistry :oops:, I need to read the documentation again :wink:

I’m using Spring.Net in an assembly part of a big application (multi-tier). My server is just a little framework who allows you to add services via pluggings (assemblies loaded at runtime via app.config) and expose those services to the client applications via remoting and via Web services (some time in the future). The assembly who is using Spring.Net is one of those pluggins (a complex one).

I have been checking a bit the Spring.Net code and I have found locks in CreateAndCacheSingletonInstance (AbstractObjectFactory.cs) and the access to the objects in GetObject is via a synchronised hashtable. I’m not sure if that’s enough, but it looks promising.

Thanks

Mark Pollack
09-14-2005, 06:41 AM
Hi,

I compared AbstractObjectFactory between the Java and C# versions with synchronization in mind and noticed one discrepency in GetAliases(string name) which I fixed. There are some internal refactorings that I didn't look at closely yet. Nevertheless, I didn't catch anything blatently out of place if you want to access an initialized context from multiple threads.

Sounds like a cool application!

Cheers,
Mark

Tolo
09-14-2005, 05:25 PM
Hi,

I compared AbstractObjectFactory between the Java and C# versions with synchronization in mind and noticed one discrepency in GetAliases(string name) which I fixed. There are some internal refactorings that I didn't look at closely yet. Nevertheless, I didn't catch anything blatently out of place if you want to access an initialized context from multiple threads.
Thank for your time to clarify that, the thread access safety is vital in my application.

Sounds like a cool application!
Yes, the application is nice. I love how easy is to create an extensible architecture with .NET, now just imagine the marvelous possibilities that Spring.Net can add to that architecture :-)

Congratulations for Spring.Net 1.0

Thanks