Skip to content

Instantly share code, notes, and snippets.

@ericdcobb
Created October 8, 2014 03:02
Show Gist options
  • Select an option

  • Save ericdcobb/2192d976c83188a9f98b to your computer and use it in GitHub Desktop.

Select an option

Save ericdcobb/2192d976c83188a9f98b to your computer and use it in GitHub Desktop.
import java.util.*;
import java.util.concurrent.*;
public class Sample {
public static void main(String[] args) throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(10);
for(int i = 0; i < 10; i++) {
final int index = i;
executorService.submit(new Runnable() {
public void run() {
System.out.println("Running task " + index);
}
});
}
System.out.println("Tasks started...");
executorService.shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment