4
@Scheduled(fixedDelay=10000)
@PostConstruct
public void someMethod(){
 //my refresh cache code here
}

If I use both @PostConstruct and @Scheduled on a bean method what will be the consequences. Will this method will be executed twice? one after the other of may be at same time ?

Dexter
  • 158
  • 2
  • 8

1 Answers1

0

The consequence will be that as soon as the class containing this method is created, the @PostConstruct will run. And the @Scheduled will trigger this method after 10_000ms, but only if @EnabledScheduling is added to the context.

The @Scheduled annotation can do both hence they can be merged like that

@Scheduled(fixedDelay=10000, initialDelay=0)
public void someMethod(){
 //my refresh cache code here
}
Valerij Dobler
  • 1,848
  • 15
  • 25