diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java b/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java
index b494e4c5ff..e25fdd3f25 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -31,8 +31,8 @@ import org.springframework.util.Assert;
*
- * Note that the TaskScheduler interface already defines methods for scheduling + * + *
Note that the TaskScheduler interface already defines methods for scheduling * tasks at fixed-rate or with fixed-delay. Both also support an optional value * for the initial delay. Those methods should be used directly whenever * possible. The value of this Trigger implementation is that it can be used @@ -68,7 +68,7 @@ public class PeriodicTrigger implements Trigger { */ public PeriodicTrigger(long period, TimeUnit timeUnit) { Assert.isTrue(period >= 0, "period must not be negative"); - this.timeUnit = (timeUnit != null) ? timeUnit : TimeUnit.MILLISECONDS; + this.timeUnit = (timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS); this.period = this.timeUnit.toMillis(period); } @@ -91,6 +91,7 @@ public class PeriodicTrigger implements Trigger { this.fixedRate = fixedRate; } + /** * Returns the time after which a task should run again. */ @@ -104,6 +105,7 @@ public class PeriodicTrigger implements Trigger { return new Date(triggerContext.lastCompletionTime().getTime() + this.period); } + @Override public boolean equals(Object obj) { if (this == obj) { @@ -113,16 +115,12 @@ public class PeriodicTrigger implements Trigger { return false; } PeriodicTrigger other = (PeriodicTrigger) obj; - return this.fixedRate == other.fixedRate - && this.initialDelay == other.initialDelay - && this.period == other.period; + return (this.fixedRate == other.fixedRate && this.initialDelay == other.initialDelay && this.period == other.period); } @Override public int hashCode() { - return (this.fixedRate ? 17 : 29) + - (int) (37 * this.period) + - (int) (41 * this.initialDelay); + return (this.fixedRate ? 17 : 29) + (int) (37 * this.period) + (int) (41 * this.initialDelay); } } diff --git a/spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskSchedulerTests.java b/spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskSchedulerTests.java index 7320cea1d1..ddaa2b0fce 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskSchedulerTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskSchedulerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -16,11 +16,6 @@ package org.springframework.scheduling.concurrent; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import java.util.Date; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; @@ -29,6 +24,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -36,6 +32,8 @@ import org.springframework.scheduling.Trigger; import org.springframework.scheduling.TriggerContext; import org.springframework.util.ErrorHandler; +import static org.junit.Assert.*; + /** * @author Mark Fisher * @since 3.0 @@ -44,7 +42,6 @@ public class ThreadPoolTaskSchedulerTests { private static final String THREAD_NAME_PREFIX = "test-"; - private final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); @@ -54,6 +51,11 @@ public class ThreadPoolTaskSchedulerTests { scheduler.afterPropertiesSet(); } + @After + public void shutdownScheduler() { + scheduler.destroy(); + } + // test methods