mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-25 07:05:49 +00:00
use "fair" ReentrantLock -- I stepped through heritrix that appeared to be deadlocked, found that the thread trying to shut down was being starved of the lock by another thread (the StarterRestarter) locking and unlocking it repeatedly, which can apparently happen because the lock was "unfair"
This commit is contained in:
@@ -107,7 +107,7 @@ public class AMQPUrlReceiver implements Lifecycle, ApplicationListener<CrawlStat
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
private transient Lock lock = new ReentrantLock();
|
||||
private transient Lock lock = new ReentrantLock(true);
|
||||
|
||||
private class StarterRestarter extends Thread {
|
||||
public StarterRestarter(String name) {
|
||||
@@ -121,17 +121,15 @@ public class AMQPUrlReceiver implements Lifecycle, ApplicationListener<CrawlStat
|
||||
lock.lockInterruptibly();
|
||||
if (!isRunning) {
|
||||
// start up again
|
||||
synchronized (AMQPUrlReceiver.this) {
|
||||
try {
|
||||
Consumer consumer = new UrlConsumer(channel());
|
||||
channel().queueDeclare(getQueueName(), false, false, true, null);
|
||||
channel().queueBind(getQueueName(), getExchange(), getQueueName());
|
||||
channel().basicConsume(getQueueName(), false, consumer);
|
||||
isRunning = true;
|
||||
logger.info("started AMQP consumer uri=" + getAmqpUri() + " exchange=" + getExchange() + " queueName=" + getQueueName());
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "problem starting AMQP consumer (will try again after 30 seconds)", e);
|
||||
}
|
||||
try {
|
||||
Consumer consumer = new UrlConsumer(channel());
|
||||
channel().queueDeclare(getQueueName(), false, false, true, null);
|
||||
channel().queueBind(getQueueName(), getExchange(), getQueueName());
|
||||
channel().basicConsume(getQueueName(), false, consumer);
|
||||
isRunning = true;
|
||||
logger.info("started AMQP consumer uri=" + getAmqpUri() + " exchange=" + getExchange() + " queueName=" + getQueueName());
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "problem starting AMQP consumer (will try again after 30 seconds)", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user