Skip to content

Commit

Permalink
Update FixedThreadPoolEx.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikraji authored May 5, 2023
1 parent 4be8733 commit a3b009f
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ public FixedThreadPoolEx(int taskId) {

@Override
public void run() {
System.out.println("Task: %d is running".formatted(taskId));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("Task: %d is running in %s".formatted(taskId, Thread.currentThread().getName()));
}

public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(6);
ExecutorService executor = Executors.newFixedThreadPool(3);

for (int i = 0; i < 10; i++) {
executor.submit(new FixedThreadPoolEx(i));
Expand Down

0 comments on commit a3b009f

Please sign in to comment.