java创建线程的4种方式--使用线程池
package com.LearnJava.Thread; import java.util.concurrent.Callable; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; class numThread2 implements Runnable{ @Override public void run() { for(int i=0;i<100;i++){ if (i%2==0){ System.out.println(i); } } } } class nT implements Callable{ @Override public Object call() throws Exception { for(int i=0;i<100;i++){ if(i%2!=0){ System.out.println(i); } } return null; } } public class ThreadPool { public static void main(String[] args) { ExecutorService executorService = Executors.newFixedThreadPool(10); executorService.execute(new numThread2()); //执行Callable方法 executorService.submit(new nT()); executorService.shutdown(); } }