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. I am using parallel stream to achieve to complete this process. 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.
In your case, the data will be processed by independently in multiple threads.