Results 1 to 6 of 6

Thread: Annotations for timer methods

  1. #1

    Default Annotations for timer methods

    I'm reading the Spring 2 reference doc on timer methods and it all seems to refer to (rather verbose) XML configuration. Is there any way to annotate a method via annotations and have Spring execute that via a timer?

    e.g.:

    //execute once an hour
    @Timer(3600000)
    public void doSomeCleanup() {}

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    In Spring 3.0, we're adding @Scheduled as well as namespace support (e.g. <scheduled-tasks/>). The namespace support is already in SVN, and the annotation is in development.

    There is also an @Async annotation (for running a method via a TaskExecutor).

  3. #3
    Join Date
    Jun 2007
    Location
    Tokyo
    Posts
    26

    Default

    Is this actually in 3.0 as I couldnt see the annotation in the latest API JavaDocs?
    Seems something that would naturally lend itself to integration with Quartz etc. i.e. something like @Scheduled(trigger=) or @Scheduled(cronExpression=)

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    The @Scheduled annotation is available on the SVN head and will be in 3.0 RC1. It supports cron without requiring Quartz now that Spring has its own cron trigger.

  5. #5
    Join Date
    Jun 2007
    Location
    Tokyo
    Posts
    26

    Default

    Thanks for the reply

    But if you wanted to use this to integrate with Quartz is that supported? For example Quartz also provides Job Persistence, Remoting etc, but it feels natural that the Job invocation itself could be just a vanilla Java method. Indeed you could also consider JobExecutionContext variables being mapped to the method invocation by annotations.

    I would of thought this would be similar to the Spring @Cached annotation where the caching implementation can be specified ?

  6. #6
    Join Date
    Oct 2009
    Posts
    3

    Default

    When using Spring 3.0: Can I use the @Scheduled annotation in a way that the actual rate/delay value is read from a property?

    I imagine something like:

    Code:
    @Scheduled(fixedDelay=#{systemProperties.blaDelay})
    public void doSomething() {
      // ...
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •