Can I have recursive function call inside parallel streams in java -
i have function model data. if parameter "entity" contains child, enclosed in child names. there 2 types of child type-a & type-b. each type function called recursively. recursive function call exits when child not have more child names.
public void modelmydata(entity entity) { if (entity.getchildnames()[0] != null) { arrays.stream(entity.getchildnames()) .collect(collectors.tolist()) .parallelstream() .foreach(childtype -> { entity.getchild(childtype).parallelstream() .foreach(child -> { modelmydata(child); }); ; }); } system.out.println("insert " + entity.getchildattributevalue()); }
the program works fine me. use of parallel stream said bad in java programming.
visit http://zeroturnaround.com/rebellabs/java-parallel-streams-are-bad-for-your-health/
should use streams instead of parallel streams?
are doing long-running operations in streams? if yes, use parallelstream, if not, don't. have read article? refers thread pool exhaustion during long-running operations. case problem/program?
as aside, arrays.aslist(entity.getchildnames()).parallelstream()....
, no need copy everything.
Comments
Post a Comment