在disruptor (版本3.3.2)中,每个事件都是Runnable (因为EventProcessor扩展了runnable)。
我正在编写一个应用程序,每当EventHandler抛出异常时,调用disruptor.start()的类需要捕获该异常并做出反应。
现在,如果EventProcessor是一个可调用的,那就很容易了。
在Disruptor中有没有其他方法来传播异常?
发布于 2015-12-21 22:23:47
我通过将一个实现接口传递给EventHandler解决了这个问题,正如Doug Lea一书所建议的那样。异常是在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);
}
});发布于 2015-11-10 09:19:10
颠覆者提供了一个ExceptionHandler,用于处理这类问题。
https://stackoverflow.com/questions/33440251
复制相似问题