BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(100000);
//方式一
ExecutorService executorService = Executors.newVirtualThreadPerTaskExecutor();
//方式二
ThreadPoolExecutor vexecutor = new ThreadPoolExecutor(10, 100, 30, TimeUnit.MINUTES, workQueue, Thread.ofVirtual().factory());
Runnable task = () -> {
System.err.println("hello Virtual");
};
for (int i = 0; i < 100000; i++) {
vexecutor.submit(task);
}
//方式三
Thread thread = Thread.ofVirtual().name("hello")
.factory().newThread(task);
thread.start();
thread.start();