spring-scheduled

Reset state before each Spring scheduled (@Scheduled) run

烂漫一生 提交于 2019-12-11 13:25:31
问题 I have a Spring Boot Batch application that needs to run daily. It reads a daily file, does some processing on its data, and writes the processed data to a database. Along the way, the application holds some state such as the file to be read (stored in the FlatFileItemReader and JobParameters ), the current date and time of the run, some file data for comparison between read items, etc. One option for scheduling is to use Spring's @Scheduled such as: @Scheduled(cron = "${schedule}") public

How to timeout a Spring Boot @Scheduled Thread

我的未来我决定 提交于 2019-12-11 03:57:55
问题 I have a Spring Boot application which runs a number of jobs at specific times of the day (configured by CRON). Now I find that the the application is running but the scheduled jobs are not getting executed. Is there any way to add a timeout to a task annotated with @Scheduled in Spring. So that even if the job is blocked or waiting, it can be killed, so that the other threads are allowed to execute smoothly. The thread can wait for a specified time and then if the task has not completed,

Replace ScheduledAnnotationBeanPostProcessor in integration tests

一笑奈何 提交于 2019-12-08 07:40:55
问题 So, I've got a spring application that uses the @Scheduled annotation to do various jobs. In prod, it works great. However this feature causes us some problems when running spock integration tests-as soon as the container starts up, all our tasks are fired and it mucks up our test runs. I'm looking for a way to turn off the scheduling functionality, but still have the container (configured with @ComponentScan) pick it up as a regular 'ol bean. Based on some legwork I've done so far, it seems

Spring Boot, Scheduled task, double invocation

做~自己de王妃 提交于 2019-12-08 04:41:17
问题 Got a pretty standard Spring Boot (1.3.5) application. Enabled scheduling with @EnableScheduling (tried on main application entry point and a @Configuration annotated class. Created a simple class with a @Scheduled method (simple fixedDelay schedule). Scheduled task executes twice (always). From what I have gathered so far, it is probably because two contexts are being loaded, and thusly picking up my beans twice. Ok. So how do I fix/prevent this double execution, since all the config is

Spring Boot, Scheduled task, double invocation

泄露秘密 提交于 2019-12-08 03:13:36
Got a pretty standard Spring Boot (1.3.5) application. Enabled scheduling with @EnableScheduling (tried on main application entry point and a @Configuration annotated class. Created a simple class with a @Scheduled method (simple fixedDelay schedule). Scheduled task executes twice (always). From what I have gathered so far, it is probably because two contexts are being loaded, and thusly picking up my beans twice. Ok. So how do I fix/prevent this double execution, since all the config is basically hidden Spring Boot magic? Framework versions: Spring Boot 1.3.5 Spring Cloud Brixton SR1 Main

Spring @Scheduled annotation

旧时模样 提交于 2019-12-05 15:50:19
How can I use @Scheduled annotation of spring dynamically? CronTrigger(String expression, TimeZone timeZone) http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/support/CronTrigger.html#CronTrigger-java.lang.String-java.util.TimeZone- As I have multiple timeZones in database, how can I pass them dynamically? I tried this in my code: TimeZone timezone = null; String timezone1 = null; public SchedulerBean(String timezone2) { this.timezone1 = timezone2; //constructor } @Scheduled(cron="0 0 8 * * ?", zone =timezone.getTimeZone(timezone1) ) //Error at this line

Spring @FeignClient , OAuth2 and @Scheduled not working

旧街凉风 提交于 2019-12-04 16:52:21
Added OAuth2FeignRequestInterceptor to handle OAuth2 @FeignClient request and I'm now seeing the following exception: *org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.oauth2ClientContext': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally

spring-boot @scheduled not running in different threads?

谁说胖子不能爱 提交于 2019-12-04 09:49:25
I am configuring a scheduled task to run in different threads. Here is the configuration code @Configuration @EnableScheduling public class SchedulerConfig implements SchedulingConfigurer { private final int POOL_SIZE = 10; @Override public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); threadPoolTaskScheduler.setPoolSize(POOL_SIZE); threadPoolTaskScheduler.setThreadNamePrefix("my-sched-pool-"); threadPoolTaskScheduler.initialize(); scheduledTaskRegistrar.setTaskScheduler

Pointcut for methods with @Scheduled Spring annotation

时光总嘲笑我的痴心妄想 提交于 2019-12-04 07:24:55
I want to have a AspectJ pointcut for methods annotated with @Scheduled . Tried different approaches but nothing worked. 1.) @Pointcut("execution(@org.springframework.scheduling.annotation.Scheduled * * (..))") public void scheduledJobs() {} @Around("scheduledJobs()") public Object profileScheduledJobs(ProceedingJoinPoint joinPoint) throws Throwable { LOG.info("testing") } 2.) @Pointcut("within(@org.springframework.scheduling.annotation.Scheduled *)") public void scheduledJobs() {} @Pointcut("execution(public * *(..))") public void publicMethod() {} @Around("scheduledJobs() && publicMethod()")

How can I use an OAuth2RestTemplate in a scheduled task?

亡梦爱人 提交于 2019-12-04 05:08:58
I have two resource servers: one that has an API for emailing notifications and one that runs scheduled tasks. When a scheduled task starts, I want to call out to the email service to notify users that their task is starting. Both services use OAuth2 for authentication. The scheduled task service has client credentials set up so that it can get an access token by presenting it's client credentials: To accomplish this, I'm using Spring Boot with Spring Security OAuth2. The Task service has an OAuth2RestTemplate to make the call out to the Email service. When the scheduled task fires up and