I'm using Spring and I have a scheduled task that makes some operations on the database. I figured out this task is executed on each pool instead I would like to have only one execution of it. For example in my log file I read:
2016-08-04 01:01:01 [pool-2-thread-1] INFO c.w.c.FleetAndCarControllerImpl - SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS
2016-08-04 01:01:01 [pool-3-thread-1] INFO c.w.c.FleetAndCarControllerImpl - SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS
I have this configuration:
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(100);
executor.setQueueCapacity(100);
executor.initialize();
return executor;
}
and this is the task:
//This task is executed every day at 01:01 a.m.
@Scheduled(cron = "0 1 1 * * ?")
public void smartQuery(){
try {
LOG.info("SCHEDULED ACTIVITY TO DELETE OLD NOTIFICATIONS");
notificationManagementServices.deleteOldNotifications();
} catch (QueryException e) {
ErrorResponse errorResponse= ErrorResponseBuilder.buildErrorResponse(e);
LOG.error("Threw exception in WakeUpDatabase::smartQuery :" + errorResponse.getStacktrace());
}
}
Is it possible?thanks