[英]Java Disruptor Handling Exceptions
在中断程序(版本3.3.2)中,每个事件都是Runnable(因为EventProcessor扩展了runnable)。
我正在编写一个应用程序,每当EventHandler引发异常时,调用interruptor.start()的类都必须捕获该异常,然后作出反应。
现在,如果EventProcessor将是Callable的话,那将很容易。
Disruptor中还有另一种传播异常的方法吗?
正如Doug Lea所建议的,我通过将实现接口传递给EventHandler解决了该问题。 异常是在LinkedList中设置的,在方法调用的最后,我检索了列表中的最后一个元素。 样例代码:
final LinkedList<Throwable> listExceptions = new LinkedList<Throwable>();
MyClassWithDisruptor at = MyClassWithDisruptor.getInstance();
at.send(message, transport, conf, new AuditExceptionHandler() {
@Override
public void handleException(final Throwable e) {
e.printStackTrace();
}
@Override
public void setException(final Exception e) throws AuditTrailException {
listExceptions.add(e);
}
});
破坏者提供了一个ExceptionHandler ,旨在处理此类问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.