该线程是 Github 问题的延续: https://github.com/spring-projects/spring-data-r2dbc/issues/194
\n语境:
\n你好,
\n我刚刚尝试了一个非常简单的示例,基于两个反应性存储库:
\n给定 br一个 r2dbc crud 存储库,以及cr另一个 r2dbc crud 存储库:
br.findAll()\n .flatMap(br -> {\n return cr.findById(br.getPropertyOne())\n .doOnNext(c -> br.setProperty2(c))\n .thenReturn(br);\n })\n .collectList().block();\nRun Code Online (Sandbox Code Playgroud)\n此代码示例永远不会完成(只有前 250 个左右的条目到达.collectList操作员)。经过一番挖掘后,onBackpressureXXX在后面添加了一些运算符findAll可以通过......删除元素或缓冲它们来“修复”问题。
在这一点上,我的理解是,r2dbc 反应存储库不使用消费者反馈机制,这消除了 r2dbc 的大部分好处。
\n我错了吗 ?有没有更好的方法来实现同样的目标?
\n谢谢 !
\n@mp911de 的建议:
\n作为一般规则,避免在另一个流处于活动状态时创建流(名言:不要交叉流)。
\n如果您想获取相关数据,那么理想情况下将所有结果收集为列表,然后运行子查询。这样,初始响应流就会被消耗,并且连接可以自由地获取其他结果。
\n像下面的代码片段这样的东西应该可以完成这项工作:
\nbr.findAll().collectList()\n .flatMap(it -> {\n\n List<Mono<Reference>> refs = new ArrayList<>();\n for (Person p : …Run Code Online (Sandbox Code Playgroud) 作为Java开发人员,我目前正在研究Go,因为我觉得它是一种有趣的语言.
首先,我决定采用我几个月前写的一个简单的Java项目,然后在Go中重新编写它以比较性能和(主要是实际)比较代码的可读性/复杂性.
Java代码示例如下:
public static void main(String[] args) {
long start = System.currentTimeMillis();
Stream<Container> s = Stream.from(new Iterator<Container>() {
int i = 0;
@Override
public boolean hasNext() {
return i < 10000000;
}
@Override
public Container next() {
return new Container(i++);
}
});
s = s.map((Container _source) -> new Container(_source.value * 2));
int j = 0;
while (s.hasNext()) {
s.next();
j++;
}
System.out.println(System.currentTimeMillis() - start);
System.out.println("j:" + j);
}
public static class Container {
int value;
public Container(int v) { …Run Code Online (Sandbox Code Playgroud)