• 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

lifespan of Spring singleton bean

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm having some trouble with a singleton spring bean in a web application context. It's being used as an ID manager, handing out unique ids to prototype-scoped beans. Anyway, I had been under the impression that once the application was deployed, Spring would create this bean once and keep it alive indefinitely as long as the deployment was active. This application has been active for several months, and the bean has been displaying behavior that is leading me to wonder if perhaps there is some inactivity trigger that is killing the bean and then re-initializing it on new request. If this is the case, I need to do something to persist the data that the bean is holding in its private instance variables... Any information about the death-cycle of singleton beans would be much appreciated, I haven't been able to find a definite answer in the Spring documentation.

Thanks,
John
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As long as the application isn't restarted and the Spring context isn't reinitialized you should always get the original instance.

But if it's important to system function this kind of information should be persistent somewhere anyway, because what if you lose power? Or redeploy the application? Or anything?
 
John Sears
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gotcha, thanks. Definitely valid concerns about if the app goes down, although for me if the entire deployment is down then the info becomes irrelevant. Just a problem if the bean was dying and the rest of the app continued.

I guess that alleviates my concern about the lifecycle, so here goes another theory to explain my problem: in a clustered environment, does Spring 2.5 automatically distribute singleton beans across the machines in the cluster? For instance, if in a single clustered app you declare a singleton bean with private instance variables, are those variables synchronized across the cluster? If one machine modifies those variables, will the modification reflect when read from another machine? I saw something about having to use Terracotta with Spring, but that seemed like more for web service calls.

Thanks!
John
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would have assumed that each jvm would get its own instance; this should be trivial to test. I'm not aware that spring has any concept of clusters out of the box.
 
John Sears
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I think I will try storing/retrieving the bean in JNDI to ensure that all clustered jvms get the same reference.
reply
    Bookmark Topic Watch Topic
  • New Topic