在中断程序(版本3.3.2)中,每个事件都是Runnable(因为EventProcessor扩展了runnable)。

我正在编写一个应用程序,每当EventHandler引发异常时,调用interruptor.start()的类都必须捕获该异常,然后作出反应。

现在,如果EventProcessor将是Callable的话,那将很容易。

Disruptor中还有另一种传播异常的方法吗?

最佳答案

我通过将实现接口传递给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);

        }
    });

关于java - Java Disruptor处理异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33440251/

10-12 06:27