public class Testphore implements Runnable {
private int id;
Testphore(int id){
this.id=id;
}
public void run() {
try {
System.out.println(this.id+"html写在这里.....");
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class TestExecutor {
public static void main(String[] args)throws Exception{
ExecutorService es = Executors.newCachedThreadPool();
for(int i=1;i<5;i++){
es.execute(new Testphore(i));
}
es.shutdown();
}
}
shutdown,执行后不再接收新任务,如果里面有任务,就执行完
本文介绍了一个简单的Java多线程应用案例,通过ExecutorService来管理并执行多个线程任务。具体实现中,定义了一个实现了Runnable接口的Testphore类,并在TestExecutor类中创建了ExecutorService实例,用于调度Testphore实例执行特定任务。
170万+

被折叠的 条评论
为什么被折叠?



