Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. // load in parallel
  2. for (Path path : paths) {
  3. ForkJoinPool.commonPool().submit(() -> {
  4. //i should start a thread on the fork join pool
  5. Graph privateGraph = new Graph();
  6.  
  7. // load private graph from path
  8.  
  9. return privateGraph;
  10. });
  11. }
  12.  
  13. // wait for all threads to be finished (future.get() waits until it returns)
  14. List<Graph> loadedSubGraphs = new ArrayList<>();
  15. for (Future<Graph> subGraphsFuture : subGraphsFutures) {
  16. try {
  17. Graph subGraph = subGraphsFuture.get();
  18. loadedSubGraphs.add(subGraph);
  19. } catch (InterruptedException | ExecutionException e) {
  20. throw new Error(e);
  21. }
  22. }
  23.  
  24. // merging
  25. Graph graph = new Graph();
  26. for (Graph loadedGraph : loadedSubGraphs) {
  27. // merge graphs into graph
  28. }
  29.  
  30. return graph;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement