fixed missing thread name revert after balancer waiting

pull/436/head
Michael Peter Christen 3 years ago
parent 9c38b1254e
commit d7b17d8935

@ -504,12 +504,14 @@ public class HostQueue implements Balancer {
rest = rest + 1000 * loops; rest = rest + 1000 * loops;
loops = 0; loops = 0;
} }
final String tname = Thread.currentThread().getName();
Thread.currentThread().setName("Balancer waiting for " + crawlEntry.url().getHost() + ": " + sleeptime + " milliseconds"); Thread.currentThread().setName("Balancer waiting for " + crawlEntry.url().getHost() + ": " + sleeptime + " milliseconds");
if (rest > 0) {try {Thread.sleep(rest);} catch (final InterruptedException e) {}} if (rest > 0) {try {Thread.sleep(rest);} catch (final InterruptedException e) {}}
for (int i = 0; i < loops; i++) { for (int i = 0; i < loops; i++) {
if (log.isInfo()) log.info("waiting for " + crawlEntry.url().getHost() + ": " + (loops - i) + " seconds remaining..."); if (log.isInfo()) log.info("waiting for " + crawlEntry.url().getHost() + ": " + (loops - i) + " seconds remaining...");
try {Thread.sleep(1000); } catch (final InterruptedException e) {} try {Thread.sleep(1000); } catch (final InterruptedException e) {}
} }
Thread.currentThread().setName(tname); // restore the name so we do not see this in the thread dump as a waiting thread
Latency.updateAfterSelection(crawlEntry.url(), robotsTime); Latency.updateAfterSelection(crawlEntry.url(), robotsTime);
} }
return crawlEntry; return crawlEntry;

@ -426,7 +426,8 @@ public class LegacyBalancer implements Balancer {
rest = rest + 1000 * loops; rest = rest + 1000 * loops;
loops = 0; loops = 0;
} }
Thread.currentThread().setName("Balancer waiting for " +crawlEntry.url().getHost() + ": " + sleeptime + " milliseconds"); final String tname = Thread.currentThread().getName();
Thread.currentThread().setName("Balancer waiting for " + crawlEntry.url().getHost() + ": " + sleeptime + " milliseconds");
synchronized(this) { synchronized(this) {
// must be synchronized here to avoid 'takeover' moves from other threads which then idle the same time which would not be enough // must be synchronized here to avoid 'takeover' moves from other threads which then idle the same time which would not be enough
if (rest > 0) {try {Thread.sleep(rest);} catch (final InterruptedException e) {}} if (rest > 0) {try {Thread.sleep(rest);} catch (final InterruptedException e) {}}
@ -435,6 +436,7 @@ public class LegacyBalancer implements Balancer {
try {Thread.sleep(1000); } catch (final InterruptedException e) {} try {Thread.sleep(1000); } catch (final InterruptedException e) {}
} }
} }
Thread.currentThread().setName(tname); // restore the name so we do not see this in the thread dump as a waiting thread
Latency.updateAfterSelection(crawlEntry.url(), robotsTime); Latency.updateAfterSelection(crawlEntry.url(), robotsTime);
} }
return crawlEntry; return crawlEntry;

Loading…
Cancel
Save