提交 cdc39802 编写于 作者: J Jesse Glick

Create a ViewJob.ReloadThread only if and when someone has a ViewJob to be reloaded.

上级 ad5cd804
...@@ -81,7 +81,7 @@ public abstract class AbstractCIBase extends Node implements ItemGroup<TopLevelI ...@@ -81,7 +81,7 @@ public abstract class AbstractCIBase extends Node implements ItemGroup<TopLevelI
v.owner = this; v.owner = this;
} }
protected void interruptReloadThread() { protected void interruptReloadThread() {
ViewJob.reloadThread.interrupt(); ViewJob.interruptReloadThread();
} }
protected void killComputer(Computer c) { protected void killComputer(Computer c) {
......
...@@ -23,18 +23,17 @@ ...@@ -23,18 +23,17 @@
*/ */
package hudson.model; package hudson.model;
import jenkins.model.Jenkins; import hudson.model.Descriptor.FormException;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedMap; import java.util.SortedMap;
import hudson.model.Descriptor.FormException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
/** /**
* {@link Job} that monitors activities that happen outside Hudson, * {@link Job} that monitors activities that happen outside Hudson,
...@@ -69,16 +68,12 @@ public abstract class ViewJob<JobT extends ViewJob<JobT,RunT>, RunT extends Run< ...@@ -69,16 +68,12 @@ public abstract class ViewJob<JobT extends ViewJob<JobT,RunT>, RunT extends Run<
*/ */
private transient volatile boolean reloadingInProgress; private transient volatile boolean reloadingInProgress;
/** private static ReloadThread reloadThread;
* {@link ExternalJob}s that need to be reloaded.
* static synchronized void interruptReloadThread() {
* This is a set, so no {@link ExternalJob}s are scheduled twice, yet if (reloadThread != null) {
* it's order is predictable, avoiding starvation. reloadThread.interrupt();
*/ }
private static final LinkedHashSet<ViewJob> reloadQueue = new LinkedHashSet<ViewJob>();
/*package*/ static final Thread reloadThread = new ReloadThread();
static {
reloadThread.start();
} }
/** /**
...@@ -120,6 +115,14 @@ public abstract class ViewJob<JobT extends ViewJob<JobT,RunT>, RunT extends Run< ...@@ -120,6 +115,14 @@ public abstract class ViewJob<JobT extends ViewJob<JobT,RunT>, RunT extends Run<
// we don't want to block the current thread, // we don't want to block the current thread,
// so reloading is done asynchronously. // so reloading is done asynchronously.
reloadingInProgress = true; reloadingInProgress = true;
Set<ViewJob> reloadQueue;
synchronized (ViewJob.class) {
if (reloadThread == null) {
reloadThread = new ReloadThread();
reloadThread.start();
}
reloadQueue = reloadThread.reloadQueue;
}
synchronized(reloadQueue) { synchronized(reloadQueue) {
reloadQueue.add(this); reloadQueue.add(this);
reloadQueue.notify(); reloadQueue.notify();
...@@ -164,6 +167,15 @@ public abstract class ViewJob<JobT extends ViewJob<JobT,RunT>, RunT extends Run< ...@@ -164,6 +167,15 @@ public abstract class ViewJob<JobT extends ViewJob<JobT,RunT>, RunT extends Run<
* Thread that reloads the {@link Run}s. * Thread that reloads the {@link Run}s.
*/ */
private static final class ReloadThread extends Thread { 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<ViewJob> reloadQueue = new LinkedHashSet<ViewJob>();
private ReloadThread() { private ReloadThread() {
setName("ViewJob reload thread"); setName("ViewJob reload thread");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册