aspose file tools*
The moose likes Other Application Frameworks and the fly likes Spring and concurrency... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring and concurrency..." Watch "Spring and concurrency..." New topic
Author

Spring and concurrency...

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
Hello,

Say I have one java object i.e. a Spring singleton. Assume one of the methods in the singleton is NOT synchronized.

Can concurrency problems occur? Do I have to synchnonize the method? Are there specific recipes for managing concurrency in Spring?

Thanks in advance,

Julien Martin.
Sergey Chunayev
Greenhorn

Joined: Jan 24, 2008
Posts: 6
Concurrency problems may occur only in situations, when your code is not synchronized. It doesn't depend on using either Spring, or any other framework. Concurrency problem in your singleton may occur if there are possibility of race conditions or dirty reads. If you use your singleton for getting some unmodifiable data, there will not be any problems, unlike the situation, if your singleton has get/set methods which aren't synchronized - here are potential hazards. The bottom line: to prevent concurrency problems use synchronization. Spring has nothing to do there, it's just a container of your classes that you have designed and implemented.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

It should be extremely rare that a singleton would have mutable state.

What are you storing in this singleton class that you are concerned about?


A good workman is known by his tools.
Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
I am not storing anything in the singleton actually.
Thanks for your replies,
Julien.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring and concurrency...