From 4fce4d0e5367046d34bbac14be768018a6dcd8ea Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 3 Sep 2012 17:46:11 +1000 Subject: [PATCH] jetty-9 ConcurrentScheduler refinements --- .../util/thread/ConcurrentScheduler.java | 7 +- .../jetty/util/thread/SchedulerTest.java | 68 ++++++++++++++++--- 2 files changed, 63 insertions(+), 12 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ConcurrentScheduler.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ConcurrentScheduler.java index 678e7a0d538..06aa23a8f30 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ConcurrentScheduler.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ConcurrentScheduler.java @@ -157,6 +157,7 @@ public class ConcurrentScheduler extends AggregateLifeCycle implements Runnable, _runner=Thread.currentThread(); while(isRunning()) { + try { // Work out how long to sleep for and execute expired events @@ -181,7 +182,10 @@ public class ConcurrentScheduler extends AggregateLifeCycle implements Runnable, } else { + long interval=event._executeAt-now; _timerQ.add(event); + if (intervalend; + if (cancel==0 || last) { expected_to_execute=true; cancel=delay+1000; } + else + expected_to_execute=false; schedules.incrementAndGet(); Scheduler.Task task=_scheduler.schedule(new Runnable() @@ -196,8 +236,12 @@ public class SchedulerTest @Override public void run() { - long lateness=System.currentTimeMillis()-expected; - executions.set(lateness); + long lateness=System.currentTimeMillis()-expected; + if (expected_to_execute) + executions.set(lateness); + else + executions.set(6666); + } },delay,TimeUnit.MILLISECONDS); @@ -205,14 +249,18 @@ public class SchedulerTest now = System.currentTimeMillis(); if (task.cancel()) { + long lateness=now-expected; if (expected_to_execute) - cancellations.set(now-expected); + cancellations.set(lateness); else cancellations.set(0); } - else if (!expected_to_execute) + else { - cancellations.set(9999); // flags failure + if (!expected_to_execute) + { + cancellations.set(9999); + } } Thread.yield();