💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` //创建线程池 ExecutorService executorService = Executors.newFixedThreadPool(2); //创建Runnable实例对象 MyRunnable myRunnable = new MyRunnable(); //从线程池中获取线程对象,调用MyRunnable的run方法 executorService.submit(myRunnable); executorService.submit(myRunnable); //排队 executorService.submit(myRunnable); executorService.submit(myRunnable); executorService.submit(myRunnable); //submit调用结束后,程序并不结束,因为线程池控制了线程的关闭 //关闭线程池 executorService.shutdown(); ``` ``` public class MyRunnable implements Runnable { @Override public void run() { try { System.out.println(Thread.currentThread().getName()); Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } } ```