ScheduledExecutorService initialize after database changes

Viewed 23

Good day! I have an Spring app with an embedded database. I want to reinitialize ScheduledExecutorService after database changes.

    @SpringBootApplication
    @FieldDefaults(level = AccessLevel.PRIVATE)
    public class SampleExecutor implements CommandLineRunner {
     
    @Autowired SampleServiceImpl serviceImpl;

    ScheduledExecutorService executor;
    
      public static void main(String[] args) {
        context = SpringApplication.run(ScreenshooterExecutor.class, args);
      }
    
   @Override
      public void run(String... args) throws Exception {
        List<DummyConfig> activeConfigs = serviceImpl.listConfigs();   
    
        executor = getScheduledThreadService(activeConfigs.size());
        for (DummyConfig config : activeConfigs) {
          //some operations for every configs
        (executor).scheduleWithFixedDelay(runnableClass, 0, config.getIntervalSec(), TimeUnit.SECONDS);
        }
    
       }
}

How it could be done in better way? I am thinking like that way below:

-shutdown current ScheduledExecutorService safely

-recreate ScheduledExecutorService which includes newest configurations.

0 Answers
Related