简体   繁体   English

Spring Async、Async with CompletableFuture 和 Java8 并行 stream 之间的区别

[英]Difference between Spring Async, Async with CompletableFuture and Java8 parallel stream

I am working on list to validate list data and then map it to Db Entity using MapStruct and finally save list in multiple table as batch process - parent and child table using Spring data JPA.我正在处理列表以验证列表数据,然后 map 使用 MapStruct 将其保存到 Db 实体,最后将列表作为批处理保存在多个表中 - 使用 Spring 数据 Z9CE3D1BD8890F16A0C7C46Z09359508 的父表和子表。 I am using parallel stream to achieve to complete this process.我正在使用并行stream来实现来完成这个过程。 Also I need result of persisted data in response where all final data I am exporting to one file to upload.此外,我需要持久数据的结果,以响应我导出到一个文件以上传的所有最终数据。

Which one suite best in my case and why?在我的情况下,哪一个套房最好,为什么?

List<Data> data; //10K records

converting into list of list with 1K records
List<List<Data>> datalist; //1K records in each list

datalist.parrallelStream.foreach( data-> 
{
    validate(data);
    List<Entity> list = mapToEntity(data);
    EntityRepo.saveAll(list); //batch_size = 1000; oracle db
}
) 

class Entity {
@Id
String id; // generating Id manually in my code using UUID. 
}

Async - This will make the processing asynchronous and make it work independently.异步 - 这将使处理异步并使其独立工作。

Java 8 parallelStream - creates subsequent threads based on the input data and processes it simultaneously. Java 8 parallelStream - 根据输入数据创建后续线程并同时对其进行处理。

In your case, the data will be processed by independently in multiple threads.在您的情况下,数据将在多个线程中独立处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以同时使用 Spring 异步和 Java8 并行 stream 吗 - Can I use Spring Async and Java8 parallel stream together 并行流和CompletableFuture之间的差异 - Difference between parallel stream and CompletableFuture Java8 - CompletableFuture - 在异步调用中按顺序运行方法 - Java8 - CompletableFuture - Running methods in async call sequentially Java 8 - 如何使用 CompletableFuture 跟踪异步并行流中调用的异常数 - Java 8 - How to track number of exceptions invoked within an async parallel stream using CompletableFuture Java8中的CompletableFuture - CompletableFuture in Java8 Java CompletableFuture thenCompose 与几个异步任务 - Java CompletableFuture thenCompose with several async tasks Java8流并行减少BiFunction累加器 - Java8 stream parallel reduce BiFunction accumulator Java8-将异步接口转换为同步接口 - Java8 - Converting an async interface into a synchronous one SpringBoot-2.1.3:使用 @Async 和 CompletableFuture 的并行方法调用 - SpringBoot-2.1.3: Parallel Methods Invocation with @Async with CompletableFuture 如何使用 CompletableFuture 将此代码转换为 Java 8 中的异步代码? 我正在使用 Spring 引导 - How to convert this code to async in Java 8 using CompletableFuture ? I am using Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM