-
Notifications
You must be signed in to change notification settings - Fork 4
Manual scheduling
Per default, every method that is elligible for being scheduled, will be scheduled by the time that its containing instance or its containing type (if the method is static
) is encountered by the Injector
.
This may lead to problems in case that the Injector
fails to initialize: It might have already scheduled some methods and thus started some threads that are now dangling in nirvana (see also discussion in #7).
Since version 2.0.0 users have the possibility to manually trigger the scheduling at a defined point (for example if your application broadcasts a certain 'ready' event). Scheduled methods can be marked to be manually started. Those methods will be scheduled only after a call to SchedulingService.startManualScheduling()
.
You can put @ManuallyStarted
on any @Scheduled
method. Those methods will not be started during Injector
initialization
Initialize GuiceAsync
with a specific flag which will cause every @Scheduled
method to behave as if it were annotated with @ManuallyStarted
:
ScheduleProperties manualScheduling = ScheduleProperties.defaultProperties().disableAutoScheduling()
GuiceAsync.createModuleWithFeatures(ScheduleFeature.withProperties(manualScheduling));
See the Getting started page for further information about GuiceAsync
initialization.
Warning: Please beware of manually started scheduled methods in non-singleton beans. In order to have those actually scheduled, you would need to call SchedulingService.startManualScheduling()
each time that such an instance has been created.