【发布时间】:2015-01-16 02:24:05
【问题描述】:
我正在使用this answer 的代码,它运行顺利。 但是,如果抛出异常,调用者代码不会捕获它。
如何在 reactor 2.0 流中捕获异常? 我想要做的是:如果抛出异常,流处理必须停止。我需要在调用者线程(首先创建蒸汽的那个)中抛出异常。
List<Map<String, Object>> data = readData();
Streams.from(data)
.flatMap(m -> Streams.just(m)
.dispatchOn(Environment.cachedDispatcher())
.map(ignored -> {throw new RuntimeException("kaboom!");}))
.buffer()
.consume(s -> System.out.println("s: " + s));
// the exception is not thrown and there is not opportunity to deal with it.
【问题讨论】:
标签: java multithreading concurrency mapreduce reactor