In a play framework project controller, I was processing a list of objects using forEach() which was working fine.
List<Post> posts = repository.getPosts();
posts.forEach(post -> {
//...some processing
anyFunc(); //<-- internally uses HttpExecutionContext
//...further processing
});
But when I tried to process these list of objects parallelly using parallelStream() to improve the performance, I lost instance of HttpExecutionContext inside parallel stream.
List<Post> posts = repository.getPosts();
posts.parallelStream().forEach(post -> {
//...some processing
anyFunc(); //<-- not able to use HttpExecutionContext now
//...further processing
});
I cannot pass HttpExecutionContext as argument to anyFunc.
Is there any way in which I can pass/set HttpExecutionContext in parallelStream()?