Subversion Repositories SmartDukaan

Rev

Rev 30374 | Go to most recent revision | 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;
6
import org.springframework.scheduling.annotation.SchedulingConfigurer;
7
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
8
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
9
 
10
@Configuration
11
public class SchedulerConfig implements SchedulingConfigurer {
12
	/**
13
	 * The pool size.
14
	 */
15
	private final int POOL_SIZE = 10;
16
 
17
	/**
18
	 * Configures the scheduler to allow multiple pools.
19
	 *
20
	 * @param taskRegistrar The task registrar.
21
	 */
30403 amit.gupta 22
	private static final Logger LOGGER = LogManager.getLogger(SchedulerConfig.class);
23
 
30374 amit.gupta 24
	@Override
25
	public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
26
		ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
27
 
30403 amit.gupta 28
		threadPoolTaskScheduler.setErrorHandler(t -> {
29
			LOGGER.info("Exception Thrown - {}", t);
30
		});
31
 
30374 amit.gupta 32
		threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
33
		threadPoolTaskScheduler.setThreadNamePrefix("scheduled-task-pool-");
34
		threadPoolTaskScheduler.initialize();
35
 
36
		taskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
37
	}
38
}