Код: Выделить всё
package com.dolphin.client;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import java.time.Duration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Slf4j
public class FeignClientApplication {
@Test
public void test() {
ExecutorService executor = Executors.newFixedThreadPool(5);
for (int i = 0; i < 10; i++) {
executor.submit(new MyTask(i));
}
}
static class MyTask implements Runnable {
private final int taskId;
public MyTask(int taskId) {
this.taskId = taskId;
}
@Override
public void run() {
try {
Thread.sleep(Duration.ofHours(1));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("Task ID : " + taskId + " performed by " + Thread.currentThread().getName());
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... k-complete