Domanda

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,

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top