diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/SimpleTaskScheduler.java b/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/SimpleTaskScheduler.java index dafd57ae5c..144159309e 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/SimpleTaskScheduler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/SimpleTaskScheduler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ package org.springframework.integration.scheduling; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.Set; -import java.util.TreeSet; import java.util.concurrent.DelayQueue; import java.util.concurrent.Delayed; import java.util.concurrent.FutureTask; @@ -37,6 +37,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.core.JdkVersion; import org.springframework.core.task.TaskExecutor; import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.MessagePublishingErrorHandler; @@ -72,7 +73,7 @@ public class SimpleTaskScheduler implements TaskScheduler, BeanFactoryAware, App private final DelayQueue> scheduledTasks = new DelayQueue>(); - private final Set> executingTasks = Collections.synchronizedSet(new TreeSet>()); + private final Set> executingTasks = Collections.synchronizedSet(new HashSet>()); private volatile boolean running; @@ -236,6 +237,8 @@ public class SimpleTaskScheduler implements TaskScheduler, BeanFactoryAware, App */ private class TriggeredTask extends FutureTask implements Delayed, ScheduledFuture { + private final Runnable task; + private final Trigger trigger; private volatile Date scheduledTime; @@ -243,6 +246,7 @@ public class SimpleTaskScheduler implements TaskScheduler, BeanFactoryAware, App public TriggeredTask(Runnable task, Trigger trigger) { super(new ErrorHandlingRunnableWrapper(task), null); + this.task = task; this.trigger = trigger; } @@ -280,10 +284,31 @@ public class SimpleTaskScheduler implements TaskScheduler, BeanFactoryAware, App public synchronized boolean cancel(boolean mayInterruptIfRunning) { if (!this.isCancelled()) { - SimpleTaskScheduler.this.scheduledTasks.remove(this); + if (JdkVersion.isAtLeastJava16()) { + SimpleTaskScheduler.this.scheduledTasks.remove(this); + } + else { // see: INT-1179 + SimpleTaskScheduler.this.scheduledTasks.removeAll(Collections.singletonList(this)); + } } return super.cancel(mayInterruptIfRunning); } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TriggeredTask)) { + return false; + } + TriggeredTask otherTask = (TriggeredTask) other; + return this.task.equals(otherTask.task) + && this.trigger.equals(otherTask.trigger); + } + + @Override + public int hashCode() { + return (this.task.hashCode() * 29) + + (this.trigger.hashCode() * 17); + } }