• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring and concurrency...

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not storing anything in the singleton actually.
Thanks for your replies,
Julien.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic