标签:线程 img src http lex attach 任务 main imp
废话不多少说,直接开始:
public class ThreadFactory {
static class ThreadPoolTask implements Runnable, Serializable {
private Object attachData;
ThreadPoolTask(Object o){
this.attachData = o;
}
@Override
public void run() {
System.out.println("开始任务:"+attachData);
}
}
public static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
10,
30,
2000,
TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<Runnable>(100));
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i <10 ; i++) {
String s = "task@"+i;
System.out.println("创建任务并提交到线程池中:" + s);
EXECUTOR.execute(new ThreadPoolTask(s));
Thread.sleep(1000);
}
}
}

标签:线程 img src http lex attach 任务 main imp
原文地址:https://www.cnblogs.com/hacker-lsr/p/12146121.html