From 078ecb834e21239ec0dc17b57a29a4efa9eede66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 27 Mar 2014 17:09:41 +0100 Subject: [PATCH] Move waiting for next reaction to start into its own method. --- .../net/pterodactylus/rhynodge/engine/Engine.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java b/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java index 2ff7666..bb42289 100644 --- a/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java +++ b/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java @@ -126,14 +126,7 @@ public class Engine extends AbstractExecutionThreadService { long waitTime = nextReaction.get().getNextTime() - System.currentTimeMillis(); logger.debug(format("Time to wait for next Reaction: %d millseconds.", waitTime)); if (waitTime > 0) { - synchronized (reactions) { - try { - logger.info(format("Waiting until %tc.", nextReaction.get().getNextTime())); - reactions.wait(waitTime); - } catch (InterruptedException ie1) { - /* we’re looping! */ - } - } + waitForNextReactionToStart(nextReaction, waitTime); /* re-start loop to check for new reactions. */ continue; @@ -196,6 +189,17 @@ public class Engine extends AbstractExecutionThreadService { } } + private void waitForNextReactionToStart(Optional nextReaction, long waitTime) { + synchronized (reactions) { + try { + logger.info(format("Waiting until %tc.", nextReaction.get().getNextTime())); + reactions.wait(waitTime); + } catch (InterruptedException ie1) { + /* we’re looping! */ + } + } + } + private Optional getNextReaction() { while (isRunning()) { synchronized (reactions) { -- 2.7.4