diff --git a/core/src/main/java/hudson/Proc.java b/core/src/main/java/hudson/Proc.java index 26d74984cf..b218017522 100644 --- a/core/src/main/java/hudson/Proc.java +++ b/core/src/main/java/hudson/Proc.java @@ -325,8 +325,8 @@ public abstract class Proc { // see https://jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors // problems like that shows up as infinite wait in join(), which confuses great many users. // So let's do a timed wait here and try to diagnose the problem - if (copier!=null) copier.join(10*1000); - if(copier2!=null) copier2.join(10*1000); + if (copier!=null) copier.join(TimeUnit.SECONDS.toMillis(10)); + if(copier2!=null) copier2.join(TimeUnit.SECONDS.toMillis(10)); if((copier!=null && copier.isAlive()) || (copier2!=null && copier2.isAlive())) { // looks like handles are leaking. // closing these handles should terminate the threads. diff --git a/core/src/main/java/hudson/ProxyConfiguration.java b/core/src/main/java/hudson/ProxyConfiguration.java index 3d73d7c78c..f6560c6a05 100644 --- a/core/src/main/java/hudson/ProxyConfiguration.java +++ b/core/src/main/java/hudson/ProxyConfiguration.java @@ -47,6 +47,7 @@ import java.net.URL; import java.net.URLConnection; import java.util.Collections; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; import javax.annotation.CheckForNull; import jenkins.model.Jenkins; @@ -85,7 +86,7 @@ public final class ProxyConfiguration extends AbstractDescribableImpl 0 ? DEFAULT_CONNECT_TIMEOUT_MILLIS : 30 * 1000); + method.getParams().setParameter("http.socket.timeout", DEFAULT_CONNECT_TIMEOUT_MILLIS > 0 ? DEFAULT_CONNECT_TIMEOUT_MILLIS : TimeUnit.SECONDS.toMillis(30)); HttpClient client = new HttpClient(); if (Util.fixEmptyAndTrim(name) != null && !isNoProxyHost(host, noProxyHost)) { diff --git a/core/src/main/java/hudson/model/ComputerPinger.java b/core/src/main/java/hudson/model/ComputerPinger.java index ecf81abceb..1cf4114a00 100644 --- a/core/src/main/java/hudson/model/ComputerPinger.java +++ b/core/src/main/java/hudson/model/ComputerPinger.java @@ -6,6 +6,7 @@ import hudson.ExtensionPoint; import java.io.IOException; import java.net.InetAddress; +import java.util.concurrent.TimeUnit; import java.util.logging.Logger; /** @@ -57,7 +58,7 @@ public abstract class ComputerPinger implements ExtensionPoint { public static class BuiltInComputerPinger extends ComputerPinger { @Override public boolean isReachable(InetAddress ia, int timeout) throws IOException { - return ia.isReachable(timeout * 1000); + return ia.isReachable((int)TimeUnit.SECONDS.toMillis(timeout)); } } diff --git a/core/src/main/java/hudson/model/DownloadService.java b/core/src/main/java/hudson/model/DownloadService.java index 27510ec1a4..f21675b019 100644 --- a/core/src/main/java/hudson/model/DownloadService.java +++ b/core/src/main/java/hudson/model/DownloadService.java @@ -46,6 +46,7 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import jenkins.model.DownloadSettings; @@ -91,7 +92,7 @@ public class DownloadService extends PageDecorator { if(Jenkins.getInstance().hasPermission(Jenkins.READ)) { long now = System.currentTimeMillis(); for (Downloadable d : Downloadable.all()) { - if(d.getDue()") .append("Behaviour.addLoadEvent(function() {") .append(" downloadService.download(") diff --git a/core/src/main/java/hudson/model/LoadStatistics.java b/core/src/main/java/hudson/model/LoadStatistics.java index 5b87c5789b..a3ddfe183e 100644 --- a/core/src/main/java/hudson/model/LoadStatistics.java +++ b/core/src/main/java/hudson/model/LoadStatistics.java @@ -51,6 +51,7 @@ import java.io.IOException; import java.io.Serializable; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.concurrent.TimeUnit; import java.util.List; import javax.annotation.CheckForNull; @@ -376,7 +377,7 @@ public abstract class LoadStatistics { /** * Load statistics clock cycle in milliseconds. Specify a small value for quickly debugging this feature and node provisioning through cloud. */ - public static int CLOCK = SystemProperties.getInteger(LoadStatistics.class.getName() + ".clock", 10 * 1000); + public static int CLOCK = SystemProperties.getInteger(LoadStatistics.class.getName() + ".clock", (int)TimeUnit.SECONDS.toMillis(10)); /** * Periodically update the load statistics average. diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index bfdacecddf..0185e4f854 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -35,6 +35,7 @@ import hudson.security.ACLContext; import hudson.util.VersionNumber; import java.nio.file.Files; import java.nio.file.InvalidPathException; +import java.util.concurrent.TimeUnit; import jenkins.security.stapler.StaplerDispatchable; import jenkins.util.SystemProperties; @@ -159,7 +160,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas /** * Read timeout when downloading plugins, defaults to 1 minute */ - private static final int PLUGIN_DOWNLOAD_READ_TIMEOUT = SystemProperties.getInteger(UpdateCenter.class.getName()+".pluginDownloadReadTimeoutSeconds", 60) * 1000; + private static final int PLUGIN_DOWNLOAD_READ_TIMEOUT = (int)TimeUnit.SECONDS.toMillis(SystemProperties.getInteger(UpdateCenter.class.getName()+".pluginDownloadReadTimeoutSeconds", 60)); public static final String PREDEFINED_UPDATE_SITE_ID = "default"; diff --git a/core/src/main/java/hudson/model/ViewJob.java b/core/src/main/java/hudson/model/ViewJob.java index 42c963a478..2bf7fa9766 100644 --- a/core/src/main/java/hudson/model/ViewJob.java +++ b/core/src/main/java/hudson/model/ViewJob.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.util.LinkedHashSet; import java.util.Set; import java.util.SortedMap; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletException; @@ -145,7 +146,7 @@ public abstract class ViewJob, RunT extends Run< reload(); } finally { reloadingInProgress = false; - nextUpdate = reloadPeriodically ? System.currentTimeMillis()+1000*60 : Long.MAX_VALUE; + nextUpdate = reloadPeriodically ? System.currentTimeMillis()+TimeUnit.MINUTES.toMillis(1) : Long.MAX_VALUE; } } @@ -187,7 +188,7 @@ public abstract class ViewJob, RunT extends Run< // reload operations might eat InterruptException, // so check the status every so often while(reloadQueue.isEmpty() && !terminating()) - reloadQueue.wait(60*1000); + reloadQueue.wait(TimeUnit.MINUTES.toMillis(1)); if(terminating()) throw new InterruptedException(); // terminate now ViewJob job = reloadQueue.iterator().next(); diff --git a/core/src/main/java/hudson/slaves/ChannelPinger.java b/core/src/main/java/hudson/slaves/ChannelPinger.java index 8493fe13fb..d92ef1bff9 100644 --- a/core/src/main/java/hudson/slaves/ChannelPinger.java +++ b/core/src/main/java/hudson/slaves/ChannelPinger.java @@ -42,6 +42,7 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.concurrent.TimeUnit; /** * Establish a periodic ping to keep connections between {@link Slave agents} @@ -184,7 +185,7 @@ public class ChannelPinger extends ComputerListener { public static void setUpPingForChannel(final Channel channel, final SlaveComputer computer, int timeoutSeconds, int intervalSeconds, final boolean analysis) { LOGGER.log(Level.FINE, "setting up ping on {0} with a {1} seconds interval and {2} seconds timeout", new Object[] {channel.getName(), intervalSeconds, timeoutSeconds}); final AtomicBoolean isInClosed = new AtomicBoolean(false); - final PingThread t = new PingThread(channel, timeoutSeconds * 1000L, intervalSeconds * 1000L) { + final PingThread t = new PingThread(channel, TimeUnit.SECONDS.toMillis(timeoutSeconds), TimeUnit.SECONDS.toMillis(intervalSeconds)) { @Override protected void onDead(Throwable cause) { if (analysis) { diff --git a/core/src/main/java/hudson/slaves/Channels.java b/core/src/main/java/hudson/slaves/Channels.java index 4b0b910b37..0657cc0ae3 100644 --- a/core/src/main/java/hudson/slaves/Channels.java +++ b/core/src/main/java/hudson/slaves/Channels.java @@ -49,6 +49,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.util.Map; import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -210,7 +211,7 @@ public class Channels { public static Channel newJVM(String displayName, TaskListener listener, JVMBuilder vmb, FilePath workDir, ClasspathBuilder classpath) throws IOException { ServerSocket serverSocket = new ServerSocket(); serverSocket.bind(new InetSocketAddress("localhost",0)); - serverSocket.setSoTimeout(10*1000); + serverSocket.setSoTimeout((int)TimeUnit.SECONDS.toMillis(10)); // use -cp + FQCN instead of -jar since remoting.jar can be rebundled (like in the case of the swarm plugin.) vmb.classpath().addJarOf(Channel.class); diff --git a/core/src/main/java/hudson/slaves/ComputerRetentionWork.java b/core/src/main/java/hudson/slaves/ComputerRetentionWork.java index 36ec97ab3b..ee246750a0 100644 --- a/core/src/main/java/hudson/slaves/ComputerRetentionWork.java +++ b/core/src/main/java/hudson/slaves/ComputerRetentionWork.java @@ -25,6 +25,7 @@ package hudson.slaves; import java.util.Map; import java.util.WeakHashMap; +import java.util.concurrent.TimeUnit; import hudson.model.Computer; import hudson.model.Queue; @@ -70,7 +71,7 @@ public class ComputerRetentionWork extends PeriodicWork { // at the moment I don't trust strategies to wait more than 60 minutes // strategies need to wait at least one minute final long waitInMins = Math.max(1, Math.min(60, c.getRetentionStrategy().check(c))); - nextCheck.put(c, startRun + waitInMins*1000*60 /*MINS->MILLIS*/); + nextCheck.put(c, startRun + TimeUnit.MINUTES.toMillis(waitInMins)); } } }); diff --git a/core/src/main/java/hudson/slaves/RetentionStrategy.java b/core/src/main/java/hudson/slaves/RetentionStrategy.java index c2237c3a56..f2137c9f3c 100644 --- a/core/src/main/java/hudson/slaves/RetentionStrategy.java +++ b/core/src/main/java/hudson/slaves/RetentionStrategy.java @@ -249,7 +249,7 @@ public abstract class RetentionStrategy extends AbstractDesc Node checkedNode = c.getNode(); if (needExecutor && checkedNode != null && checkedNode.canTake(item) == null) { demandMilliseconds = System.currentTimeMillis() - item.buildableStartMilliseconds; - needComputer = demandMilliseconds > inDemandDelay * 1000 * 60 /*MINS->MILLIS*/; + needComputer = demandMilliseconds > TimeUnit.MINUTES.toMillis(inDemandDelay); break; } } @@ -262,7 +262,7 @@ public abstract class RetentionStrategy extends AbstractDesc } } else if (c.isIdle()) { final long idleMilliseconds = System.currentTimeMillis() - c.getIdleStartMilliseconds(); - if (idleMilliseconds > idleDelay * 1000 * 60 /*MINS->MILLIS*/) { + if (idleMilliseconds > TimeUnit.MINUTES.toMillis(idleDelay)) { // we've been idle for long enough logger.log(Level.INFO, "Disconnecting computer {0} as it has been idle for {1}", new Object[]{c.getName(), Util.getTimeSpanString(idleMilliseconds)}); diff --git a/core/src/main/java/hudson/triggers/Trigger.java b/core/src/main/java/hudson/triggers/Trigger.java index 12df0f05f9..4423c0137d 100644 --- a/core/src/main/java/hudson/triggers/Trigger.java +++ b/core/src/main/java/hudson/triggers/Trigger.java @@ -52,6 +52,7 @@ import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; @@ -215,7 +216,7 @@ public abstract class Trigger implements Describable> } public long getInitialDelay() { - return MIN - (Calendar.getInstance().get(Calendar.SECOND) * 1000); + return MIN - TimeUnit.SECONDS.toMillis(Calendar.getInstance().get(Calendar.SECOND)); } public void doRun() { diff --git a/core/src/main/java/hudson/util/ProcessTree.java b/core/src/main/java/hudson/util/ProcessTree.java index 73438b2989..fd33d2f995 100644 --- a/core/src/main/java/hudson/util/ProcessTree.java +++ b/core/src/main/java/hudson/util/ProcessTree.java @@ -68,6 +68,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.SortedMap; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -550,7 +551,7 @@ public abstract class ProcessTree implements Iterable, IProcessTree, } // after that wait for it to cease to exist - long deadline = System.nanoTime() + softKillWaitSeconds * 1000000000; + long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(softKillWaitSeconds); int sleepTime = 10; // initially we sleep briefly, then sleep up to 1sec do { if (!p.isRunning()) { @@ -759,7 +760,7 @@ public abstract class ProcessTree implements Iterable, IProcessTree, */ public void kill() throws InterruptedException { // after sending SIGTERM, wait for the process to cease to exist - long deadline = System.nanoTime() + softKillWaitSeconds * 1000000000; + long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(softKillWaitSeconds); kill(deadline); } @@ -798,7 +799,7 @@ public abstract class ProcessTree implements Iterable, IProcessTree, public void killRecursively() throws InterruptedException { // after sending SIGTERM, wait for the processes to cease to exist until the deadline - long deadline = System.nanoTime() + softKillWaitSeconds * 1000000000; + long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(softKillWaitSeconds); killRecursively(deadline); } diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index a75df79b0a..5f363a6f40 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -3830,7 +3830,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve while (isQuietingDown && (timeout <= 0 || System.currentTimeMillis() < waitUntil) && !RestartListener.isAllReady()) { - Thread.sleep(1000); + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); } } return new HttpRedirect("."); @@ -3889,7 +3889,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve // if the result isn't available in 5 sec, ignore that. // this is a precaution against hang nodes - long endTime = System.currentTimeMillis() + 5000; + long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(5); Map> r = new HashMap>(); for (Entry>> e : future.entrySet()) { @@ -4246,7 +4246,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve ACL.impersonate(ACL.SYSTEM); // give some time for the browser to load the "reloading" page - Thread.sleep(5000); + Thread.sleep(TimeUnit.SECONDS.toMillis(5)); LOGGER.info(String.format("Restarting VM as requested by %s",exitUser)); for (RestartListener listener : RestartListener.all()) listener.onRestart(); @@ -4282,7 +4282,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve servletContext.setAttribute("app",new HudsonIsRestarting()); // give some time for the browser to load the "reloading" page LOGGER.info("Restart in 10 seconds"); - Thread.sleep(10000); + Thread.sleep(TimeUnit.SECONDS.toMillis(10)); LOGGER.info(String.format("Restarting VM as requested by %s",exitUser)); for (RestartListener listener : RestartListener.all()) listener.onRestart(); @@ -4587,7 +4587,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve if(ALLOWED_RESOURCE_EXTENSIONS.contains(extension)) { URL url = pluginManager.uberClassLoader.getResource(path); if(url!=null) { - long expires = MetaClass.NO_CACHE ? 0 : 365L * 24 * 60 * 60 * 1000; /*1 year*/ + long expires = MetaClass.NO_CACHE ? 0 : TimeUnit.DAYS.toMillis(365); rsp.serveFile(req,url,expires); return; } diff --git a/test/src/test/java/hudson/model/WorkspaceCleanupThreadTest.java b/test/src/test/java/hudson/model/WorkspaceCleanupThreadTest.java index dc2c8e0c5c..49057a1245 100644 --- a/test/src/test/java/hudson/model/WorkspaceCleanupThreadTest.java +++ b/test/src/test/java/hudson/model/WorkspaceCleanupThreadTest.java @@ -33,6 +33,7 @@ import hudson.util.StreamTaskListener; import java.io.File; import java.io.IOException; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import jenkins.MasterToSlaveFileCallable; @@ -135,7 +136,7 @@ public class WorkspaceCleanupThreadTest { FilePath ws = createOldWorkspaceOn(r.jenkins, p); createOldWorkspaceOn(r.createOnlineSlave(), p); - long twoDaysOld = System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000; + long twoDaysOld = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(2); ws.act(new Touch(twoDaysOld)); WorkspaceCleanupThread.retainForDays = 3; @@ -151,7 +152,7 @@ public class WorkspaceCleanupThreadTest { @Test @WithoutJenkins public void recurrencePeriodIsInHours() { assertEquals( - WorkspaceCleanupThread.recurrencePeriodHours * 60 * 60 * 1000 , + TimeUnit.HOURS.toMillis(WorkspaceCleanupThread.recurrencePeriodHours), new WorkspaceCleanupThread().getRecurrencePeriod() ); }