Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
30374 amit.gupta 1
package com.smartdukaan.cron.config;
2
 
30403 amit.gupta 3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
30374 amit.gupta 5
import org.springframework.context.annotation.Configuration;
34153 amit.gupta 6
import org.springframework.context.annotation.Profile;
7
import org.springframework.scheduling.annotation.EnableScheduling;
30374 amit.gupta 8
import org.springframework.scheduling.annotation.SchedulingConfigurer;
9
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
10
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
11
 
12
@Configuration
34153 amit.gupta 13
@EnableScheduling
14
@Profile("scheduled")
30374 amit.gupta 15
public class SchedulerConfig implements SchedulingConfigurer {
16
	/**
17
	 * The pool size.
18
	 */
19
	private final int POOL_SIZE = 10;
20
 
34153 amit.gupta 21
	/**"prod"
30374 amit.gupta 22
	 * Configures the scheduler to allow multiple pools.
23
	 *
24
	 * @param taskRegistrar The task registrar.
25
	 */
30403 amit.gupta 26
	private static final Logger LOGGER = LogManager.getLogger(SchedulerConfig.class);
27
 
30374 amit.gupta 28
	@Override
29
	public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
30
		ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
31
 
30403 amit.gupta 32
		threadPoolTaskScheduler.setErrorHandler(t -> {
33
			LOGGER.info("Exception Thrown - {}", t);
34
		});
35
 
30374 amit.gupta 36
		threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
37
		threadPoolTaskScheduler.setThreadNamePrefix("scheduled-task-pool-");
38
		threadPoolTaskScheduler.initialize();
39
 
40
		taskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
41
	}
42
}