From cdc3980221983a3247c9405831d5bd623b084681 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 28 Mar 2014 14:31:29 -0400 Subject: [PATCH] Create a ViewJob.ReloadThread only if and when someone has a ViewJob to be reloaded. --- .../java/hudson/model/AbstractCIBase.java | 2 +- core/src/main/java/hudson/model/ViewJob.java | 46 ++++++++++++------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractCIBase.java b/core/src/main/java/hudson/model/AbstractCIBase.java index 19cc8cfbf7..3d8f0858e4 100644 --- a/core/src/main/java/hudson/model/AbstractCIBase.java +++ b/core/src/main/java/hudson/model/AbstractCIBase.java @@ -81,7 +81,7 @@ public abstract class AbstractCIBase extends Node implements ItemGroup, RunT extends Run< */ private transient volatile boolean reloadingInProgress; - /** - * {@link ExternalJob}s that need to be reloaded. - * - * This is a set, so no {@link ExternalJob}s are scheduled twice, yet - * it's order is predictable, avoiding starvation. - */ - private static final LinkedHashSet reloadQueue = new LinkedHashSet(); - /*package*/ static final Thread reloadThread = new ReloadThread(); - static { - reloadThread.start(); + private static ReloadThread reloadThread; + + static synchronized void interruptReloadThread() { + if (reloadThread != null) { + reloadThread.interrupt(); + } } /** @@ -120,6 +115,14 @@ public abstract class ViewJob, RunT extends Run< // we don't want to block the current thread, // so reloading is done asynchronously. reloadingInProgress = true; + Set reloadQueue; + synchronized (ViewJob.class) { + if (reloadThread == null) { + reloadThread = new ReloadThread(); + reloadThread.start(); + } + reloadQueue = reloadThread.reloadQueue; + } synchronized(reloadQueue) { reloadQueue.add(this); reloadQueue.notify(); @@ -164,6 +167,15 @@ public abstract class ViewJob, RunT extends Run< * Thread that reloads the {@link Run}s. */ private static final class ReloadThread extends Thread { + + /** + * {@link ExternalJob}s that need to be reloaded. + * + * This is a set, so no {@link ExternalJob}s are scheduled twice, yet + * it's order is predictable, avoiding starvation. + */ + final Set reloadQueue = new LinkedHashSet(); + private ReloadThread() { setName("ViewJob reload thread"); } -- GitLab