import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@Slf4j
public class TestExecute {
public static void main(String[] args) {
// 创建线程数量为2的线程池执行任务
Executor threadPool = Executors.newFixedThreadPool(2);
threadPool.execute(new Runnable() {
@SneakyThrows
public void run() {
while (true) {
log.info("十秒钟执行一次A任务");
Thread.sleep(10000);
}
}
});
threadPool.execute(new Runnable() {
@SneakyThrows
public void run() {
while (true) {
log.info("两秒钟执行一次B任务");
Thread.sleep(2000);
}
}
});
}
}
11-21
523
11-27
1368