• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring and concurrency...

 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not storing anything in the singleton actually.
Thanks for your replies,
Julien.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic