提交 3bf7e661 编写于 作者: K kohsuke

if a subtask is aborted, all the executors should be aborted.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34627 71c3de6d-444a-0410-be80-ed276b4c234a
上级 839ba1d7
......@@ -106,7 +106,9 @@ public class Executor extends Thread implements ModelObject {
SubTask task;
try {
synchronized (queue) {// perform this state change as an atomic operation wrt other queue operations
// transition from idle to building.
// perform this state change as an atomic operation wrt other queue operations
synchronized (queue) {
workUnit = grabJob();
workUnit.setExecutor(this);
task = workUnit.work;
......@@ -137,6 +139,7 @@ public class Executor extends Thread implements ModelObject {
// a bug in the code, but we don't want the executor to die,
// so just leave some info and go on to build other things
LOGGER.log(Level.SEVERE, "Executor threw an exception", e);
workUnit.context.abort(e);
problems = e;
} finally {
setName(threadName);
......@@ -144,6 +147,7 @@ public class Executor extends Thread implements ModelObject {
try {
workUnit.context.synchronizeEnd(executable,problems,finishTime - startTime);
} catch (InterruptedException e) {
workUnit.context.abort(e);
continue;
}
}
......
......@@ -46,8 +46,10 @@ class Latch {
this.n = n;
}
public synchronized void abort() {
public synchronized void abort(Throwable cause) {
interrupted = new AbortException();
if (cause!=null)
interrupted.initCause(cause);
notifyAll();
}
......@@ -55,13 +57,14 @@ class Latch {
public synchronized void synchronize() throws InterruptedException {
check(n);
boolean success=false;
try {
onCriteriaMet();
success=true;
} finally {
if (!success)
abort();
} catch (Error e) {
abort(e);
throw e;
} catch (RuntimeException e) {
abort(e);
throw e;
}
check(n*2);
......
......@@ -131,8 +131,18 @@ public final class WorkUnitContext {
}
}
public void abort() {
startLatch.abort();
endLatch.abort();
/**
* When one of the work unit is aborted, call this method to abort all the other work units.
*/
public void abort(Throwable cause) {
startLatch.abort(cause);
endLatch.abort(cause);
Thread c = Thread.currentThread();
for (WorkUnit wu : workUnits) {
Executor e = wu.getExecutor();
if (e!=null && e!=c)
e.interrupt();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册