Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the standard Timer rather than our own ScheduledExecutorService #84

Merged
merged 3 commits into from
Nov 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@
import hudson.Launcher;
import hudson.PluginWrapper;
import hudson.Util;
import hudson.init.Terminator;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.remoting.Channel;
import hudson.remoting.DaemonThreadFactory;
import hudson.remoting.NamingThreadFactory;
import hudson.remoting.RemoteOutputStream;
import hudson.remoting.VirtualChannel;
import hudson.slaves.WorkspaceList;
Expand Down Expand Up @@ -71,8 +68,6 @@
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -81,6 +76,7 @@
import jenkins.MasterToSlaveFileCallable;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlaveCallable;
import jenkins.util.Timer;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.commons.io.output.CountingOutputStream;
Expand Down Expand Up @@ -563,21 +559,6 @@ public FilePath getLastLocationFile(FilePath workspace) throws IOException, Inte
private static final long serialVersionUID = 1L;
}

private static ScheduledExecutorService watchService;
private synchronized static ScheduledExecutorService watchService() {
if (watchService == null) {
// TODO 2.105+ use ClassLoaderSanityThreadFactory
watchService = new /*ErrorLogging*/ScheduledThreadPoolExecutor(5, new NamingThreadFactory(new DaemonThreadFactory(), "FileMonitoringTask watcher"));
}
return watchService;
}
@Terminator public static synchronized void shutDownWatchService() {
if (watchService != null) {
watchService.shutdownNow();
watchService = null;
}
}

private static class StartWatching extends MasterToSlaveFileCallable<Void> {

private static final long serialVersionUID = 1L;
Expand All @@ -593,7 +574,7 @@ private static class StartWatching extends MasterToSlaveFileCallable<Void> {
}

@Override public Void invoke(File workspace, VirtualChannel channel) throws IOException, InterruptedException {
watchService().submit(new Watcher(controller, new FilePath(workspace), handler, listener));
Timer.get().submit(new Watcher(controller, new FilePath(workspace), handler, listener));
return null;
}

Expand Down Expand Up @@ -655,7 +636,7 @@ private static class Watcher implements Runnable {
}
// Could use an adaptive timeout as in DurableTaskStep.Execution in polling mode,
// though less relevant here since there is no network overhead to the check.
watchService().schedule(this, 100, TimeUnit.MILLISECONDS);
Timer.get().schedule(this, 100, TimeUnit.MILLISECONDS);
}
} catch (Exception x) {
// note that LOGGER here is going to the agent log, not master log
Expand Down