diff --git a/src/main/java/cn/hezhaohui/threadpool/ThreadPoolApplication.java b/src/main/java/cn/hezhaohui/threadpool/ThreadPoolApplication.java index 92f6f3f..0058288 100644 --- a/src/main/java/cn/hezhaohui/threadpool/ThreadPoolApplication.java +++ b/src/main/java/cn/hezhaohui/threadpool/ThreadPoolApplication.java @@ -1,11 +1,34 @@ package cn.hezhaohui.threadpool; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import lombok.extern.slf4j.Slf4j; -@SpringBootApplication +import java.util.Random; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +@Slf4j public class ThreadPoolApplication { - public static void main(String[] args) { - SpringApplication.run(ThreadPoolApplication.class, args); + public static void main(String[] args) throws InterruptedException { + ExecutorService executorService = Executors.newFixedThreadPool(2); + for (int i = 0; i < 100000000; i++) { + executorService.execute(() -> { + StringBuilder builder = new StringBuilder(); + int random = new Random().nextInt(1000); + for (int j = 1; j < random; j++) { + builder.append(j); + } + try { + TimeUnit.HOURS.sleep(1); + } catch (InterruptedException e) { + log.error("[Error]"); + } + log.info(builder.toString()); + + }); + } + + executorService.shutdown(); + executorService.awaitTermination(1, TimeUnit.HOURS); } }