Skip to content

Commit 407ecf7

Browse files
igor-suhorukovjhoeller
authored andcommitted
to get rid of "magic" time constants
1 parent ed7684d commit 407ecf7

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Map;
2121
import java.util.Properties;
2222
import java.util.concurrent.Executor;
23+
import java.util.concurrent.TimeUnit;
2324
import javax.sql.DataSource;
2425

2526
import org.quartz.Scheduler;
@@ -697,7 +698,7 @@ protected void startScheduler(final Scheduler scheduler, final int startupDelay)
697698
@Override
698699
public void run() {
699700
try {
700-
Thread.sleep(startupDelay * 1000);
701+
Thread.sleep(TimeUnit.SECONDS.toMillis(startupDelay));
701702
}
702703
catch (InterruptedException ex) {
703704
Thread.currentThread().interrupt();

spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.sql.Connection;
2020
import java.sql.SQLException;
2121
import java.sql.Statement;
22+
import java.util.concurrent.TimeUnit;
2223
import javax.sql.DataSource;
2324

2425
import org.apache.commons.logging.Log;
@@ -108,7 +109,7 @@ public void afterPropertiesSet() {
108109
try {
109110
boolean validated = false;
110111
long beginTime = System.currentTimeMillis();
111-
long deadLine = beginTime + this.timeout * 1000;
112+
long deadLine = beginTime + TimeUnit.SECONDS.toMillis(this.timeout);
112113
SQLException latestEx = null;
113114

114115
while (!validated && System.currentTimeMillis() < deadLine) {
@@ -139,7 +140,7 @@ public void afterPropertiesSet() {
139140
}
140141

141142
if (!validated) {
142-
Thread.sleep(this.interval * 1000);
143+
Thread.sleep(TimeUnit.SECONDS.toMillis(this.interval));
143144
}
144145
}
145146

@@ -148,7 +149,7 @@ public void afterPropertiesSet() {
148149
"Database has not started up within " + this.timeout + " seconds", latestEx);
149150
}
150151

151-
float duration = (System.currentTimeMillis() - beginTime) / 1000;
152+
float duration = (System.currentTimeMillis() - beginTime)*1f / 1000;
152153
if (logger.isInfoEnabled()) {
153154
logger.info("Database startup detected after " + duration + " seconds");
154155
}

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.concurrent.ConcurrentHashMap;
2626
import java.util.concurrent.ExecutionException;
2727
import java.util.concurrent.ScheduledFuture;
28+
import java.util.concurrent.TimeUnit;
2829
import java.util.concurrent.atomic.AtomicInteger;
2930

3031
import org.apache.commons.logging.Log;
@@ -87,7 +88,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
8788
@Nullable
8889
private TaskScheduler taskScheduler;
8990

90-
private long receiptTimeLimit = 15 * 1000;
91+
private long receiptTimeLimit = TimeUnit.SECONDS.toMillis(15);
9192

9293
private volatile boolean autoReceiptEnabled;
9394

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.messaging.simp.stomp;
1818

1919
import java.util.Arrays;
20+
import java.util.concurrent.TimeUnit;
2021

2122
import org.springframework.lang.Nullable;
2223
import org.springframework.messaging.converter.MessageConverter;
@@ -48,7 +49,7 @@ public abstract class StompClientSupport {
4849

4950
private long[] defaultHeartbeat = new long[] {10000, 10000};
5051

51-
private long receiptTimeLimit = 15 * 1000;
52+
private long receiptTimeLimit = TimeUnit.SECONDS.toMillis(15);
5253

5354

5455
/**

spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.messaging.simp.user;
1818

1919
import java.util.concurrent.ScheduledFuture;
20+
import java.util.concurrent.TimeUnit;
2021

2122
import org.springframework.context.ApplicationListener;
2223
import org.springframework.lang.Nullable;
@@ -56,7 +57,7 @@ public class UserRegistryMessageHandler implements MessageHandler, ApplicationLi
5657
@Nullable
5758
private volatile ScheduledFuture<?> scheduledFuture;
5859

59-
private long registryExpirationPeriod = 20 * 1000;
60+
private long registryExpirationPeriod = TimeUnit.SECONDS.toMillis(20);
6061

6162

6263
/**

spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class WebSocketMessageBrokerStats {
7575
@Nullable
7676
private ScheduledFuture<?> loggingTask;
7777

78-
private long loggingPeriod = 30 * 60 * 1000;
78+
private long loggingPeriod = TimeUnit.MINUTES.toMillis(30);
7979

8080

8181
public void setSubProtocolWebSocketHandler(SubProtocolWebSocketHandler webSocketHandler) {
@@ -114,7 +114,7 @@ public void setOutboundChannelExecutor(ThreadPoolTaskExecutor outboundChannelExe
114114

115115
public void setSockJsTaskScheduler(ThreadPoolTaskScheduler sockJsTaskScheduler) {
116116
this.sockJsTaskScheduler = sockJsTaskScheduler.getScheduledThreadPoolExecutor();
117-
this.loggingTask = initLoggingTask(60 * 1000);
117+
this.loggingTask = initLoggingTask(TimeUnit.MINUTES.toMillis(1));
118118
}
119119

120120
@Nullable

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
8787

8888
private boolean sessionCookieNeeded = true;
8989

90-
private long heartbeatTime = 25 * 1000;
90+
private long heartbeatTime = TimeUnit.SECONDS.toMillis(25);
9191

92-
private long disconnectDelay = 5 * 1000;
92+
private long disconnectDelay = TimeUnit.SECONDS.toMillis(5 );
9393

9494
private int httpMessageCacheSize = 100;
9595

0 commit comments

Comments
 (0)