From 5111d85cf0dfb98679800812fbaa5b79186a259a Mon Sep 17 00:00:00 2001 From: Bartosz Firyn <bartosz.firyn@alcatel-lucent.com> Date: Wed, 20 Feb 2013 22:39:08 +0100 Subject: [PATCH] Change delay mechanism in WebcamDiscoveryService --- .../sarxos/webcam/WebcamDiscoveryService.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDiscoveryService.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDiscoveryService.java index a090f8ca..b5973f6f 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDiscoveryService.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDiscoveryService.java @@ -142,9 +142,20 @@ public void run() { // wait initial time interval since devices has been initially // discovered + Object monitor = new Object(); + do { - delay(); + synchronized (monitor) { + try { + monitor.wait(support.getScanInterval()); + } catch (InterruptedException e) { + if (LOG.isTraceEnabled()) { + LOG.error("Interrupted", e); + } + break; + } + } WebcamDiscoveryListener[] listeners = Webcam.getDiscoveryListeners(); @@ -267,14 +278,6 @@ private static void notifyWebcamFound(Webcam webcam, WebcamDiscoveryListener[] l } } - private void delay() { - try { - Thread.sleep(support.getScanInterval()); - } catch (InterruptedException e) { - throw new WebcamException(e); - } - } - /** * Stop discovery service. */