• 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

Set time attribute in application scope in managed bean scope

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

I have a bean which load all the master data from database.
As these are not frequently changed tables so i have putted in application scope.But it updates only when i restart the application as per definition of application scope.

I need to define some time interval like 5 hr 10 hr after this i need to again call this bean.

Please any one let me know can i achieve this functionality in JSF.


Thanks & Regards
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Pintu!

You don't "call beans", you call methods in the beans. In particular, what you'd like to do is periodically call a method that refreshes the data in your bean (Model).

There are a number of ways of doing this. One of the most common is to simply set up a timer task in a ServletContextListener. Every 5 minutes, it fires, invoking the bean's "refresh" method.

One thing you do need to be careful of, however. Since the application-scope bean is shared between multiple threads (requests), you need to ensure that your update and data retrieval code is thread-safe. Otherwise you can end up with scrambled data.
 
pintu pandey
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Tim,
Thanks for your reply.
I got your point but my requirement is something different.

I explain here.

I have a dropdown list of country(This is coming from a master table.)
My requirement is we dont want to load this combo every time because values of dropdown is coming from database.
This country list is populating on transaction pages.

As master table do not change frequently,so we want to load this data on some specific time in a day and rest time it should be populated from cache.

Overall my requirement is to populate master data on a time from database rest time it should come from cache.

I think i explain correctly this time.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cache = application-scope bean.

But to update the cache you either need to periodically refresh it while handling requests or you need to setup a regular schedule for updating it from a ServletContextListener. You want that to happen at a certain time. So you can either schedule it from a ServletContextListener using a scheduler such as Quartz or you can make a web "update" request and have an external schedule process (such as cron) post it. ServletContextListener is good because everything is bundled together neatly in a single app, but external request is good because you can invoke it off-schedule if changes were made that you want to take effect immediately. Of course, there's nothing that says you cannot do both.

Your problem is a common one, and I've got more than one webapp that has this kind of code in it. The only really critical thing is that, as I said, you need to be thread-safe in your updating or people could end up pulling the menu while it's being changed.
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic