Java中多线程类ExecutorService的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hoho_12/article/details/84982649
package com.threadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolTest {
	
	public void mainMethod(){
		//获取线程池类
		ExecutorService threadPool = Executors.newFixedThreadPool(5);
		String str = "hello";
		//执行方法
		AutoTest autoTest = new AutoTest(str);
		threadPool.execute(autoTest);		
	}	
	
	public void syso(String str){
		System.out.println(str);
	}	
		
	class AutoTest implements Runnable{
		private String str;
		public AutoTest(String s){
			str = s;
		}	
		@Override
		public void run() {
			syso(str);
		}
	}

}

猜你喜欢

转载自blog.csdn.net/hoho_12/article/details/84982649