From 2830a407ba70b5f47ce2462def0394d0ebde3c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mih=C3=A1ly=20Kuprivecz?= Date: Fri, 28 Apr 2017 12:19:57 +0200 Subject: [PATCH] some fixes for testing in event queue --- .../java/com/iluwatar/event/queue/Audio.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/event-queue/src/main/java/com/iluwatar/event/queue/Audio.java b/event-queue/src/main/java/com/iluwatar/event/queue/Audio.java index 9175eeffa..b482acca1 100644 --- a/event-queue/src/main/java/com/iluwatar/event/queue/Audio.java +++ b/event-queue/src/main/java/com/iluwatar/event/queue/Audio.java @@ -52,7 +52,7 @@ public class Audio { /** * This method stops the Update Method's thread. */ - public static void stopService() { + public static synchronized void stopService() { if (updateThread != null) { updateThread.interrupt(); } @@ -62,11 +62,12 @@ public class Audio { * This method stops the Update Method's thread. * @return boolean */ - public static boolean isServiceRunning() { - if (updateThread != null) { - return updateThread.isAlive(); + public static synchronized boolean isServiceRunning() { + if (updateThread != null && updateThread.isAlive() ) { + return true; + } else { + return false; } - return false; } /** @@ -83,6 +84,13 @@ public class Audio { } }); } + startThread(); + } + + /** + * This is a synchronized thread starter + */ + public static synchronized void startThread() { if (!updateThread.isAlive()) { updateThread.start(); headIndex = 0;