Created
February 15, 2018 10:03
-
-
Save visparashar/ca4c0f8aaf88c738cd5b61fd7a7c9a3e to your computer and use it in GitHub Desktop.
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
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