Reputation: 2994
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,
Upvotes: 0
Views: 979
Reputation: 120871
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.
Upvotes: 1