package shixunTest; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Properties; import java.util.Scanner; import java.util.Vector; public class ThreadPoolMore { static int num; public void init(){ //读取属性文件 InputStream in= this.getClass().getResourceAsStream("config.properties"); Properties p=new Properties(); try { p.load(in); int num=Integer.parseInt(p.getProperty("num")); ThreadPoolMore.num=num; System.out.println("当前模拟线程个数为:"+num); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { ThreadPoolMore test=new ThreadPoolMore(); test.init(); //初始化num大小的线程池 ThreadPool threadPoool=new ThreadPool(ThreadPoolMore.num); //模拟执行任务 while(true){ System.out.println("请输入任务 名称"); Scanner scanner=new Scanner(System.in); String taskName=scanner.next(); threadPoool.executeTask(taskName); } } } class ThreadPool{ private int maxpoolsize; private Vector vThreads=new Vector(); public static ArrayList taskLists=new ArrayList(); //新建maxpoolsize个线程 public ThreadPool(int maxpoolsize){ this.maxpoolsize=maxpoolsize; for(int i=0;i=vThreads.size()){ System.out.println("线程池已满,请等待。。。"); try { Thread.sleep(10*1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } //线程池循环查看线程中的空闲线程,如果有空闲线程,将任务分配给它执行 for(int i=0;i