版权声明:本文为博主原创文章,未经博主允许不得转载。 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);
}
}
}