以反应方式创建文件(Reactor / WebFlux)?
Creating a File in reactive way (Reactor / WebFlux)?
我想以反应方式创建一个临时文件以避免阻塞调用。
Mono.fromCallable {
Files.createTempFile(null, ".zip")
}
.flatMap { path: Path ->
DataBufferUtils.write(
webclient.get().uri("/large-file.zip").retrieve()
.bodyToFlux(DataBuffer::class.java),
path,
StandardOpenOption.CREATE
).then(Mono.just(path))
}
但是,我在 IDEA 中收到有关方法 createTempFile
:
的警告
Possibly blocking call in non-blocking context could lead to thread starvation
有没有办法以真正反应式的方式创建这样的文件?
看来我需要等待Loom:
On Linux, we plan to use io_uring for asynchronous file I/O, and in the meantime we’re using the ForkJoinPool.ManagedBlocker mechanism to smooth over blocking file I/O operations by adding more OS threads to the worker pool when a worker is blocked.
(来源:https://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html)
我想以反应方式创建一个临时文件以避免阻塞调用。
Mono.fromCallable {
Files.createTempFile(null, ".zip")
}
.flatMap { path: Path ->
DataBufferUtils.write(
webclient.get().uri("/large-file.zip").retrieve()
.bodyToFlux(DataBuffer::class.java),
path,
StandardOpenOption.CREATE
).then(Mono.just(path))
}
但是,我在 IDEA 中收到有关方法 createTempFile
:
Possibly blocking call in non-blocking context could lead to thread starvation
有没有办法以真正反应式的方式创建这样的文件?
看来我需要等待Loom:
On Linux, we plan to use io_uring for asynchronous file I/O, and in the meantime we’re using the ForkJoinPool.ManagedBlocker mechanism to smooth over blocking file I/O operations by adding more OS threads to the worker pool when a worker is blocked.
(来源:https://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html)