小编vin*_*ray的帖子

如何并行处理 Flux 事件?

我有需要丰富的传入事件流,然后在它们到达时并行处理。

我认为 Project Reactor 是为这项工作定制的,但在我的测试中,所有处理似乎都是连续完成的。

下面是一些测试代码:

ExecutorService executor = Executors.newFixedThreadPool(10);
System.out.println("Main thread: " + Thread.currentThread());
Flux<String> tick = Flux.interval(Duration.of(10, ChronoUnit.MILLIS))
        .map(i-> {
            System.out.println("ReactorTests.test " + Thread.currentThread());
            sleep(1000L); // simulate IO delay
            return String.format("String %d", i);
        })
        .take(3)
//    .subscribeOn(Schedulers.elastic());
//    .subscribeOn(Schedulers.newParallel("test"));
//    .subscribeOn(Schedulers.fromExecutor(executor));
;
tick.subscribe(x ->System.out.println("Subscribe thread: " + Thread.currentThread()), 
               System.out::println, 
               ()-> System.out.println("Done"));
System.out.println("DONE AND DONE");
Run Code Online (Sandbox Code Playgroud)

我已经尝试取消注释每个注释行,但是在每种情况下,输出都表明使用相同的线程来处理所有事件

Main thread: Thread[main,5,main]
[DEBUG] (main) Using Console logging
DONE AND DONE
ReactorTests.test Thread[parallel-1,5,main]
Subscribe thread: Thread[parallel-1,5,main]
ReactorTests.test Thread[parallel-1,5,main]
Subscribe thread: Thread[parallel-1,5,main]
ReactorTests.test Thread[parallel-1,5,main] …
Run Code Online (Sandbox Code Playgroud)

project-reactor

7
推荐指数
1
解决办法
2798
查看次数

如何获取传入Java启动的-D参数

我将某些-D环境变量作为VM选项传递给Java服务器应用程序.

我需要从应用程序中检索这些变量,但是当我使用System.getProperties()时,我得到了所有这些,以及在操作系统级别定义的所有系统属性,我对此不感兴趣.

有没有办法发现-D参数?

java properties

5
推荐指数
1
解决办法
306
查看次数

标签 统计

java ×1

project-reactor ×1

properties ×1