Shut down harvester thread pool when it's done. (#223)
* Shut down harvester thread pool when it's done. * Use ExecutorService to create harvester threads; name thread pool threads to match other ice4j threads.
This commit is contained in:
parent
34c2ce50ec
commit
5a299cd694
@ -17,6 +17,7 @@ package org.ice4j.ice.harvest;
|
|||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.jetbrains.annotations.*;
|
import org.jetbrains.annotations.*;
|
||||||
|
import org.jitsi.utils.concurrent.*;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -283,42 +284,49 @@ public class MappingCandidateHarvesters
|
|||||||
|
|
||||||
// Now run discover() on all created harvesters in parallel and pick
|
// Now run discover() on all created harvesters in parallel and pick
|
||||||
// the ones which succeeded.
|
// the ones which succeeded.
|
||||||
ExecutorService es = Executors.newFixedThreadPool(tasks.size());
|
ExecutorService es = ExecutorFactory.createFixedThreadPool(tasks.size(),
|
||||||
|
"ice4j.Harvester-executor-");
|
||||||
|
|
||||||
List<Future<StunMappingCandidateHarvester>> futures;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
futures = es.invokeAll(tasks);
|
List<Future<StunMappingCandidateHarvester>> futures;
|
||||||
}
|
|
||||||
catch (InterruptedException ie)
|
|
||||||
{
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
return stunHarvesters;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Future<StunMappingCandidateHarvester> future : futures)
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StunMappingCandidateHarvester harvester = future.get();
|
futures = es.invokeAll(tasks);
|
||||||
|
|
||||||
// The STUN server replied successfully.
|
|
||||||
if (harvester.getMask() != null)
|
|
||||||
{
|
|
||||||
stunHarvesters.add(harvester);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (ExecutionException ee)
|
catch (InterruptedException ie)
|
||||||
{
|
|
||||||
// The harvester failed for some reason, discard it.
|
|
||||||
}
|
|
||||||
catch(InterruptedException ie)
|
|
||||||
{
|
{
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new RuntimeException(ie);
|
return stunHarvesters;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Future<StunMappingCandidateHarvester> future : futures)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StunMappingCandidateHarvester harvester = future.get();
|
||||||
|
|
||||||
|
// The STUN server replied successfully.
|
||||||
|
if (harvester.getMask() != null)
|
||||||
|
{
|
||||||
|
stunHarvesters.add(harvester);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ExecutionException ee)
|
||||||
|
{
|
||||||
|
// The harvester failed for some reason, discard it.
|
||||||
|
}
|
||||||
|
catch (InterruptedException ie)
|
||||||
|
{
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new RuntimeException(ie);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
es.shutdown();
|
||||||
|
}
|
||||||
return stunHarvesters;
|
return stunHarvesters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user