Created
May 19, 2014 11:08
-
-
Save thrakt/19ffd822ab16234daeb8 to your computer and use it in GitHub Desktop.
Java8でListをある程度まとめて並列処理 ref: http://qiita.com/thrakt/items/62d05c2ea0675f0f996f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Map<String, Object>> rows = new ArrayList<>(); // データ入れる | |
rows.parallelStream().forEach(row -> { | |
LOG.info("something to do."); | |
LOG.info(row); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Map<String, Object>> rows = new ArrayList<>(); // データ入れる | |
for (int start = 0; start < rows.size();) { | |
int end = start + 100; | |
if (end > oldRows.size()) { | |
end = oldRows.size(); | |
} | |
List<Map<String, Object>> subList = rows.subList(start, end); | |
ForkJoinPool.commonPool().execute(() -> { | |
LOG.info("something to doooooooooooooo."); | |
subList.forEach(row -> { | |
LOG.info(row); | |
}); | |
}); | |
start = end; | |
} | |
}); | |
// 終了待機 | |
while (!ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.HOURS)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment