0

I have a class 'ABC' which gets initialized lazily at the time of context-up depending on some external parameters. Class has one method 'test' with @Scheduled annotation which does some scheduled activity.

public class ABC{
    @Scheduled(fixedDelay=100000)
    public void test(){
    }
}

XML file is like this:

<bean id="abc" class="com.test.ABC" lazy-init="true" />

Irrespective of whether I initialize the class or not, @Scheduled method is always called.

Is there any way to run @Scheduled method only when class is initialized?

Thanks,

Ralph
  • 118,862
  • 56
  • 287
  • 383
instanceOfObject
  • 2,936
  • 5
  • 49
  • 85

1 Answers1

1

You can try to use a @PostConstruct method to intialize a programmatic timer. And then use this programmatic timer instead of @Schedule.

@See skaffman`s answer on this question about programmatic timer.

dma_k
  • 10,431
  • 16
  • 76
  • 128
Ralph
  • 118,862
  • 56
  • 287
  • 383