Skip to content

Instantly share code, notes, and snippets.

@visparashar
Created February 15, 2018 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visparashar/ca4c0f8aaf88c738cd5b61fd7a7c9a3e to your computer and use it in GitHub Desktop.
Save visparashar/ca4c0f8aaf88c738cd5b61fd7a7c9a3e to your computer and use it in GitHub Desktop.
public class ThreadPoolDemo {
public static void main(String[] args) {
ExecutorService service = Executors.newFixedThreadPool(2);
for(int i =0;i<5;i++){
service.execute(new Processor());
// Future f =service.submit(new Processor());
}
service.shutdown();
}
}
class Processor implements Runnable{
@Override
public void run() {
System.out.println("Starting "+Thread.currentThread());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Completed" +Thread.currentThread());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment