Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // load in parallel
- for (Path path : paths) {
- ForkJoinPool.commonPool().submit(() -> {
- //i should start a thread on the fork join pool
- Graph privateGraph = new Graph();
- // load private graph from path
- return privateGraph;
- });
- }
- // wait for all threads to be finished (future.get() waits until it returns)
- List<Graph> loadedSubGraphs = new ArrayList<>();
- for (Future<Graph> subGraphsFuture : subGraphsFutures) {
- try {
- Graph subGraph = subGraphsFuture.get();
- loadedSubGraphs.add(subGraph);
- } catch (InterruptedException | ExecutionException e) {
- throw new Error(e);
- }
- }
- // merging
- Graph graph = new Graph();
- for (Graph loadedGraph : loadedSubGraphs) {
- // merge graphs into graph
- }
- return graph;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement