Skip to content

Choosing the ScheduledExecutorService

Simon Taddiken edited this page Aug 20, 2016 · 1 revision

Methods are called asynchronously using an ExecutorService. If not further specified (see below) a default executor will be used for running the annotated method. The framework does allow to customize which executor will be used. For each annotated method you can define a Key that is used to look up the actual Executor implementation from the Injector. You can use the @Executor annotation for specifying the Executor type. Optionally you can put a binding annotation to further refine the Key.

    @Scheduled
    @CronTrigger("...")
    @Scheduler(MyVerySpecialCustomExecutor.class)
    public void scheduledMethod2() {
        // ScheduledExecutorService will be retrieved using Key.get(MyVerySpecialCustomExecutor.class)
    }
    
    @Scheduled
    @CronTrigger("...")
    @Scheduler(MySchedulerImplementation.class)
    @Named("mainScheduler")
    public void scheduledMethod2() {
        // ScheduledExecutorService will be retrieved using Key.get(MySchedulerImplementation.class, 
        //     Names.named("mainScheduler"))
    }
}