有没有办法停止SedaConsumer
而不等待BlockingQueue.take(pollTimeout, ...)
返回?我的应用程序中有很多 sedas,正常关闭需要很长时间。当 DefaultShutdownStrategy
shutdown sedaConsumers
时,队列中不再有消息,也不会再生成任何消息(因为之前实现了路由关闭)。因此每个 sedaConsumer
必须等待大约 1 秒。
是否可以对seda强制执行doStop而不是prepareShutdown?或者中断工作线程?
我知道我可以减少pollTimeout
,但我担心这会影响运行时性能。
最佳答案
try {
// use the end user configured poll timeout
exchange = queue.poll(pollTimeout, TimeUnit.MILLISECONDS);
// Omitted
} catch (InterruptedException e) {
LOG.debug("Sleep interrupted, are we stopping? {}", isStopping() || isStopped());
continue;
} catch (Throwable e) {
if (exchange != null) {
getExceptionHandler().handleException("Error processing exchange", exchange, e);
} else {
getExceptionHandler().handleException(e);
}
}
此构造在线程中的大多数位置都可以抛出 InterruptedException,因此如果使用者正在停止并被中断,它将正常停止。
关于java - 如何加快seda关闭速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29610800/