kill lagging search threads

This commit is contained in:
Adithya Abraham Philip
2015-07-02 04:10:38 +05:30
parent 39c752727e
commit f44f966dc8

View File

@@ -45,6 +45,7 @@ public class CloudSearch {
}
final ImportKeysList results = new ImportKeysList(servers.size());
ArrayList<Thread> searchThreads = new ArrayList<>();
for (final Keyserver keyserver : servers) {
Runnable r = new Runnable() {
@Override
@@ -57,19 +58,25 @@ public class CloudSearch {
results.finishedAdding(); // notifies if all searchers done
}
};
new Thread(r).start();
Thread searchThread = new Thread(r);
searchThreads.add(searchThread);
searchThread.start();
}
// wait for either all the searches to come back, or 10 seconds
synchronized(results) {
synchronized (results) {
try {
results.wait(10 * SECONDS);
for (Thread thread : searchThreads) {
// kill threads that haven't returned yet
thread.interrupt();
}
} catch (InterruptedException e) {
}
}
if (results.outstandingSuppliers() > 0) {
String message = "Launched " + servers.size() + " cloud searchers, but" +
String message = "Launched " + servers.size() + " cloud searchers, but" +
results.outstandingSuppliers() + "failed to complete.";
problems.add(new Keyserver.QueryFailedException(message));
}