Coordinating Runnable tasks using CountDownLatch


/ Published in: Java
Save to your folder(s)

A simple way to parallelize a for loop in Java. Wrapping each iteration (task) with a Runnable, executing them with an ExecutorService (to pool threads) and coordinating them with a simple CountDownLatch.

Due to Java's lack of closures, this simple scenario is rather verbose.

URL: http://java.sun.com/j2se/1.6.0/docs/api/java/util/concurrent/CountDownLatch.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.