看下列代码
这个警告的说在非阻塞上下文中阻塞调用可能会导致线程饥饿
解决方法:
private Mono<Path> createTempFile(String name) {
String prefix = name +"_";
return Mono.defer(() -> {
Path dir1 = Path.of(dir);
return isExist(dir1).flatMap(path -> createFile(path, prefix, ".jpg"));
}).subscribeOn(Schedulers.boundedElastic());
}
private Mono<Path> isExist(Path path){
return Mono.fromCallable(()->{
if(Files.notExists(path)){
return Files.createDirectories(path);
}
return path;
}).subscribeOn(Schedulers.boundedElastic());
}
private Mono<Path> createFile(Path path, String prefix, String suffix){
return Mono.fromCallable(()->Files.createTempFile(path,prefix, ".jpg"))
.subscribeOn(Schedulers.boundedElastic());
}