Remove reliance on afterExecute from WorkQueue Some JVM implementations aren't passing our decorated Task object to the afterExecute() method. Instead they passing their own internal wrapper around the Runnable to us. This is pretty useless, because we can't obtain the task id in order to remove it from the queue. Instead rely on the finally block in the tasks' own run() method. We know it will run after the code is executed, allowing us to do the cleanup we expected to perform. Bug: issue 483 Change-Id: I3a4584949b591601cf923f3a90715f5d5fb69bbb Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java index ead6a6f..567bd33 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java
@@ -181,20 +181,6 @@ throw new UnsupportedOperationException("Callable not implemented"); } - @SuppressWarnings("unchecked") - @Override - protected void afterExecute(Runnable r, Throwable t) { - if (r instanceof Task) { - final Task<?> task = (Task<?>) r; - if (!task.isPeriodic()) { - remove(task); - } - } else { - log.error("Non task object in queue: " + r.getClass() + ": " + r); - } - super.afterExecute(r, t); - } - void remove(final Task<?> task) { all.remove(task.getTaskId(), task); } @@ -330,6 +316,8 @@ } finally { if (isPeriodic()) { running.set(false); + } else { + executor.remove(this); } } }