org.springframework.scheduling.config.ScheduledTask Java Examples

The following examples show how to use org.springframework.scheduling.config.ScheduledTask. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScheduledAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return all currently scheduled tasks, from {@link Scheduled} methods
 * as well as from programmatic {@link SchedulingConfigurer} interaction.
 * @since 5.0.2
 */
@Override
public Set<ScheduledTask> getScheduledTasks() {
	Set<ScheduledTask> result = new LinkedHashSet<>();
	synchronized (this.scheduledTasks) {
		Collection<Set<ScheduledTask>> allTasks = this.scheduledTasks.values();
		for (Set<ScheduledTask> tasks : allTasks) {
			result.addAll(tasks);
		}
	}
	result.addAll(this.registrar.getScheduledTasks());
	return result;
}
 
Example #2
Source File: ScheduledAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void postProcessBeforeDestruction(Object bean, String beanName) {
	Set<ScheduledTask> tasks;
	synchronized (this.scheduledTasks) {
		tasks = this.scheduledTasks.remove(bean);
	}
	if (tasks != null) {
		for (ScheduledTask task : tasks) {
			task.cancel();
		}
	}
}
 
Example #3
Source File: ScheduledAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void destroy() {
	synchronized (this.scheduledTasks) {
		Collection<Set<ScheduledTask>> allTasks = this.scheduledTasks.values();
		for (Set<ScheduledTask> tasks : allTasks) {
			for (ScheduledTask task : tasks) {
				task.cancel();
			}
		}
		this.scheduledTasks.clear();
	}
	this.registrar.destroy();
}
 
Example #4
Source File: ScheduledAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return all currently scheduled tasks, from {@link Scheduled} methods
 * as well as from programmatic {@link SchedulingConfigurer} interaction.
 * @since 5.0.2
 */
@Override
public Set<ScheduledTask> getScheduledTasks() {
	Set<ScheduledTask> result = new LinkedHashSet<>();
	synchronized (this.scheduledTasks) {
		Collection<Set<ScheduledTask>> allTasks = this.scheduledTasks.values();
		for (Set<ScheduledTask> tasks : allTasks) {
			result.addAll(tasks);
		}
	}
	result.addAll(this.registrar.getScheduledTasks());
	return result;
}
 
Example #5
Source File: ScheduledAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void postProcessBeforeDestruction(Object bean, String beanName) {
	Set<ScheduledTask> tasks;
	synchronized (this.scheduledTasks) {
		tasks = this.scheduledTasks.remove(bean);
	}
	if (tasks != null) {
		for (ScheduledTask task : tasks) {
			task.cancel();
		}
	}
}
 
Example #6
Source File: ScheduledAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void destroy() {
	synchronized (this.scheduledTasks) {
		Collection<Set<ScheduledTask>> allTasks = this.scheduledTasks.values();
		for (Set<ScheduledTask> tasks : allTasks) {
			for (ScheduledTask task : tasks) {
				task.cancel();
			}
		}
		this.scheduledTasks.clear();
	}
	this.registrar.destroy();
}
 
Example #7
Source File: ChaosMonkeySchedulerTest.java    From chaos-monkey-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
void shouldScheduleATask() {
  String schedule = "*/1 * * * * ?";
  ScheduledTask scheduledTask = mock(ScheduledTask.class);
  when(config.getRuntimeAssaultCronExpression()).thenReturn(schedule);
  when(registrar.scheduleCronTask(any())).thenReturn(scheduledTask);

  new ChaosMonkeyScheduler(registrar, config, scope);

  verify(registrar).scheduleCronTask(argThat(hasScheduleLike(schedule)));
}
 
Example #8
Source File: ChaosMonkeySchedulerTest.java    From chaos-monkey-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
void shouldScheduleANewTaskAfterAnUpdate() {
  String schedule = "*/1 * * * * ?";
  ScheduledTask oldTask = mock(ScheduledTask.class);
  ScheduledTask newTask = mock(ScheduledTask.class);
  when(config.getRuntimeAssaultCronExpression()).thenReturn(schedule);
  when(registrar.scheduleCronTask(any())).thenReturn(oldTask, newTask);

  ChaosMonkeyScheduler cms = new ChaosMonkeyScheduler(registrar, config, scope);
  cms.reloadConfig();

  verify(registrar, times(2)).scheduleCronTask(argThat(hasScheduleLike(schedule)));
  verify(oldTask).cancel();
}
 
Example #9
Source File: ScheduledAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void postProcessBeforeDestruction(Object bean, String beanName) {
	Set<ScheduledTask> tasks;
	synchronized (this.scheduledTasks) {
		tasks = this.scheduledTasks.remove(bean);
	}
	if (tasks != null) {
		for (ScheduledTask task : tasks) {
			task.cancel();
		}
	}
}
 
Example #10
Source File: ScheduledAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void destroy() {
	synchronized (this.scheduledTasks) {
		Collection<Set<ScheduledTask>> allTasks = this.scheduledTasks.values();
		for (Set<ScheduledTask> tasks : allTasks) {
			for (ScheduledTask task : tasks) {
				task.cancel();
			}
		}
		this.scheduledTasks.clear();
	}
	this.registrar.destroy();
}