Created
April 2, 2023 13:01
-
-
Save surabhisuman/8eafe62f577bea7d94b8b77a6a1bda9f 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
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class ThreadPool { | |
private static class DoSomething implements Runnable { | |
private int taskId; | |
public DoSomething(int taskId) { | |
this.taskId = taskId; | |
} | |
@Override | |
public void run() { | |
System.out.println("Currently running task " + taskId + " by " + Thread.currentThread().getName()); | |
} | |
} | |
public static void main(String[] args) { | |
ExecutorService service = Executors.newFixedThreadPool(10); // creating a fixed size thread pool | |
for (int i = 1; i <= 100; i++) { | |
service.submit(new DoSomething(i)); | |
} | |
service.shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment