Subversion Repositories SmartDukaan

Rev

Rev 30403 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.smartdukaan.cron.config;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

@Configuration
@EnableScheduling
@Profile("scheduled")
public class SchedulerConfig implements SchedulingConfigurer {
        /**
         * The pool size.
         */
        private final int POOL_SIZE = 10;

        /**"prod"
         * Configures the scheduler to allow multiple pools.
         *
         * @param taskRegistrar The task registrar.
         */
        private static final Logger LOGGER = LogManager.getLogger(SchedulerConfig.class);

        @Override
        public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
                ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();

                threadPoolTaskScheduler.setErrorHandler(t -> {
                        LOGGER.info("Exception Thrown - {}", t);
                });

                threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
                threadPoolTaskScheduler.setThreadNamePrefix("scheduled-task-pool-");
                threadPoolTaskScheduler.initialize();

                taskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
        }
}