diff --git a/src/main/java/com/alibaba/wasp/executor/EventHandler.java b/src/main/java/com/alibaba/wasp/executor/EventHandler.java index a22307d..c62fc54 100644 --- a/src/main/java/com/alibaba/wasp/executor/EventHandler.java +++ b/src/main/java/com/alibaba/wasp/executor/EventHandler.java @@ -56,6 +56,7 @@ public abstract class EventHandler implements Runnable, Comparable { private static final Log LOG = LogFactory.getLog(EventHandler.class); + private static volatile boolean hasExecuted; // type of event this object represents protected EventType eventType; @@ -192,6 +193,7 @@ public EventHandler(Server server, EventType eventType) { public void run() { Span chunk = Trace.startSpan(Thread.currentThread().getName(), parent, Sampler.ALWAYS); + hasExecuted = true; try { if (getListener() != null) getListener().beforeProcess(this); @@ -205,6 +207,10 @@ public void run() { } } + public static boolean getExecutedStatus() { + return hasExecuted; + } + /** * This method is the main processing loop to be implemented by the various * subclasses. diff --git a/src/test/java/com/alibaba/wasp/executor/TestExecutorService.java b/src/test/java/com/alibaba/wasp/executor/TestExecutorService.java index 10915d7..eeeafe4 100644 --- a/src/test/java/com/alibaba/wasp/executor/TestExecutorService.java +++ b/src/test/java/com/alibaba/wasp/executor/TestExecutorService.java @@ -79,6 +79,9 @@ public void testExecutorService() throws Exception { int tries = 0; while (counter.get() < maxThreads && tries < maxTries) { LOG.info("Waiting for all event handlers to start..."); + while (!EventHandler.getExecutedStatus()) { + Thread.yield(); + } Thread.sleep(sleepInterval); tries++; }