[英]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.