From 8f5125165804b8356946bb29e094615e799ae70c Mon Sep 17 00:00:00 2001 From: chenzo Date: Wed, 12 Sep 2012 10:03:22 +0000 Subject: [PATCH] Applies first part of Carl Hasselskog patch: UPnP potential deadlock, Connector closing, CandidateHarvesterSet thread pool merged. --- src/org/ice4j/ice/harvest/CandidateHarvesterSet.java | 10 ++++++---- src/org/ice4j/ice/harvest/UPNPHarvester.java | 4 ++-- src/org/ice4j/stack/Connector.java | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/org/ice4j/ice/harvest/CandidateHarvesterSet.java b/src/org/ice4j/ice/harvest/CandidateHarvesterSet.java index d292545..bc81517 100644 --- a/src/org/ice4j/ice/harvest/CandidateHarvesterSet.java +++ b/src/org/ice4j/ice/harvest/CandidateHarvesterSet.java @@ -36,6 +36,11 @@ public class CandidateHarvesterSet private final Collection elements = new LinkedList(); + /** + * A pool of thread used for gathering process. + */ + private static ExecutorService threadPool = Executors.newCachedThreadPool(); + /** * Initializes a new CandidateHarvesterSet instance. */ @@ -82,10 +87,7 @@ public class CandidateHarvesterSet { synchronized (elements) { - harvest( - elements.iterator(), - component, - Executors.newCachedThreadPool()); + harvest(elements.iterator(), component, threadPool); } } diff --git a/src/org/ice4j/ice/harvest/UPNPHarvester.java b/src/org/ice4j/ice/harvest/UPNPHarvester.java index 28b7865..b782656 100644 --- a/src/org/ice4j/ice/harvest/UPNPHarvester.java +++ b/src/org/ice4j/ice/harvest/UPNPHarvester.java @@ -96,9 +96,9 @@ public class UPNPHarvester wanIPThread.start(); wanPPPThread.start(); - while(finishThreads != 2) + synchronized(rootSync) { - synchronized(rootSync) + while(finishThreads != 2) { rootSync.wait(); } diff --git a/src/org/ice4j/stack/Connector.java b/src/org/ice4j/stack/Connector.java index 96ec6aa..1007c5d 100644 --- a/src/org/ice4j/stack/Connector.java +++ b/src/org/ice4j/stack/Connector.java @@ -246,6 +246,7 @@ class Connector synchronized(sockLock) { this.running = false; + this.sock.close(); this.sock = null; } }