Announcement Announcement Module
Collapse
No announcement yet.
reload a bean periodically Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • reload a bean periodically

    Hi everybody,

    I have a bean service that works as a static list,basically this service makes some query to db at initialization time.

    As this list changed every 12 hours, i'm was wondering if it could be possible to configure some spring listener or timer so this bean is reloaded

    Here is my bean conf., the reload method makes a query to db at initialization time

    Code:
    <bean id="staticListService" class="com.service.StaticListService" init-method="reload"/>
    Thanks

  • #2
    Look in the Spring doc for information about Timer support.

    I would suggest that you create a timer task (using either JDK timers or Quartz) that when run will get your bean from the context (you could make it context aware) and call the method that does the db query.

    Is that what you're looking for?

    Comment


    • #3
      yeah, thanks, i'll take a look at it

      Comment


      • #4
        I would suggest that you create a timer task (using either JDK timers or Quartz) that when run will get your bean from the context (you could make it context aware) and call the method that does the db query.
        Why? There is a MethodInvokingTimerTaskFactoryBean which you can simply configure to invoke a certain method on a certain bean. You don't have to create anything, you can basically just configure everything without writing a single line of code just xml.

        Comment


        • #5
          As Martin says, using MethodInvokingTimerTaskFactoryBean allows you to avoid creating an intermediate class to call your method. You should probably just read the "Using JDK Timer support" section of the Spring doc. That shows you how to set up the schedule for invoking the method.

          Comment

          Working...
          X