From 52c829fb0d4336d527e407e39379034a52daa354 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 22 Sep 2017 17:35:32 +0200 Subject: [PATCH] Wrap the discoverers into separate threads Fixes #6350 (the regression was introduced with b2241dadf8f7777564bc5595265caa53a1fec399 ) Thanks git-bisect :) --- arduino-core/src/cc/arduino/packages/Discovery.java | 2 +- arduino-core/src/cc/arduino/packages/DiscoveryManager.java | 2 +- .../cc/arduino/packages/discoverers/NetworkDiscovery.java | 7 ++++++- .../cc/arduino/packages/discoverers/SerialDiscovery.java | 7 ++++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arduino-core/src/cc/arduino/packages/Discovery.java b/arduino-core/src/cc/arduino/packages/Discovery.java index 911fcc2f6..5bbd740cd 100644 --- a/arduino-core/src/cc/arduino/packages/Discovery.java +++ b/arduino-core/src/cc/arduino/packages/Discovery.java @@ -31,7 +31,7 @@ package cc.arduino.packages; import java.util.List; -public interface Discovery { +public interface Discovery extends Runnable { /** * Start discovery service diff --git a/arduino-core/src/cc/arduino/packages/DiscoveryManager.java b/arduino-core/src/cc/arduino/packages/DiscoveryManager.java index 01259e8e0..b1ec50d85 100644 --- a/arduino-core/src/cc/arduino/packages/DiscoveryManager.java +++ b/arduino-core/src/cc/arduino/packages/DiscoveryManager.java @@ -51,7 +51,7 @@ public class DiscoveryManager { // Start all discoverers for (Discovery d : discoverers) { try { - d.start(); + new Thread(d).start(); } catch (Exception e) { System.err.println(tr("Error starting discovery method: ") + d.getClass()); e.printStackTrace(); diff --git a/arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java b/arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java index 4ed374a57..ecf678783 100644 --- a/arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java +++ b/arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java @@ -39,7 +39,7 @@ import java.util.*; import cc.arduino.packages.discoverers.network.BoardReachabilityFilter; -public class NetworkDiscovery implements Discovery, ServiceListener { +public class NetworkDiscovery implements Discovery, ServiceListener, Runnable { private final List reachableBoardPorts = new LinkedList<>(); private final List boardPortsDiscoveredWithJmDNS = new LinkedList<>(); @@ -138,6 +138,11 @@ public class NetworkDiscovery implements Discovery, ServiceListener { } + @Override + public void run() { + start(); + } + @Override public void start() { jmdns = JmmDNS.Factory.getInstance(); diff --git a/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java b/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java index da3593332..4de78552c 100644 --- a/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java +++ b/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java @@ -37,7 +37,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Timer; -public class SerialDiscovery implements Discovery { +public class SerialDiscovery implements Discovery, Runnable { private Timer serialBoardsListerTimer; private final List serialBoardPorts; @@ -85,6 +85,11 @@ public class SerialDiscovery implements Discovery { public void pausePolling(boolean param) { serialBoardsLister.pausePolling = param;} + @Override + public void run() { + start(); + } + @Override public void start() { this.serialBoardsListerTimer = new Timer(SerialBoardsLister.class.getName());