Browse Source

Polishing

pull/218/merge
Juergen Hoeller 12 years ago committed by unknown
parent
commit
d5af9dc0a5
  1. 18
      spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java
  2. 16
      spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskSchedulerTests.java

18
spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java

@ -1,5 +1,5 @@ @@ -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; @@ -31,8 +31,8 @@ import org.springframework.util.Assert;
* <emphasis>completion</emphasis> time). To measure the interval between the
* scheduled <emphasis>start</emphasis> time of each execution instead, set the
* 'fixedRate' property to {@code true}.
* <p>
* Note that the TaskScheduler interface already defines methods for scheduling
*
* <p>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 { @@ -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 { @@ -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 { @@ -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 { @@ -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);
}
}

16
spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskSchedulerTests.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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; @@ -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; @@ -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 { @@ -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 { @@ -54,6 +51,11 @@ public class ThreadPoolTaskSchedulerTests {
scheduler.afterPropertiesSet();
}
@After
public void shutdownScheduler() {
scheduler.destroy();
}
// test methods

Loading…
Cancel
Save