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,

4

1 に答える 1

1

@PostConstructメソッドを使用して、プログラムによるタイマーを初期化することができます。そして、代わりにこのプログラムタイマーを使用します@Schedule

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

于 2013-03-11T07:58:33.297 に答える