标签:ati util executors mina term rri str ide static
汇总自己用到的高并发模型
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class test { public static void main(String[] args) { ExecutorService executorService = Executors.newFixedThreadPool(10); for (int k = 0; k < 10; k++) { final int t = k; executorService.submit(new Runnable() { @Override public void run() { getID(t); } }); } // 平滑的关闭ExecutorService,当所有提交任务执行完毕,线程池即被关闭 executorService.shutdown(); while (true) { // isTerminated当调用shutdown()方法后,并且所有提交的任务完成后返回为true if (executorService.isTerminated()) { break; } } } public static int getID(int id) { return id; } }
标签:ati util executors mina term rri str ide static
原文地址:https://www.cnblogs.com/flypig258/p/12187489.html