import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPool {
public static void main(String[] args) throws Exception {
ExecutorService pool = Executors.newCachedThreadPool();
for(int i = 1; i <= 10; i++){
pool.execute(new Runnable() {
public void run() {
System.out.println("thread name: " + Thread.currentThread().getName());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}
Thread.sleep(10000);
System.out.println("----------------------------------");
for(int i = 1; i <= 15; i++){
pool.execute(new Runnable() {
public void run() {
System.out.println("thread name: " + Thread.currentThread().getName());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
spark中executor执行Driver发送的task,放入线程池中执行原理
最新推荐文章于 2022-08-02 10:06:33 发布
博客探讨了在Spark中Executor如何接收并执行Driver发送的Task。通过ExecutorService创建线程池,ExecutorService的execute方法用于提交Runnable任务。示例代码展示了如何创建和使用线程池执行任务,以及Task的序列化与反序列化过程。
摘要由CSDN通过智能技术生成