我想知道在java中开发线程池的最佳方法是什么 执行多任务,以及如何在此示例程序执行时堆栈内存。 请解释一下实现线程池的最佳方法是什么?
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Pattern;
class A implements Runnable {
@Override
public void run() {
System.out.println("A "+Thread.currentThread().getName());
}
}
class B implements Runnable {
@Override
public void run() {
System.out.println("B "+Thread.currentThread().getName());
}
}
class C implements Runnable {
@Override
public void run() {
System.out.println("C "+Thread.currentThread().getName());
}
}
public class threadrunner {
public static void main(String[] args) {
ExecutorService bn = Executors.newFixedThreadPool(2);
Runnable t1 = new A();
Runnable t2 = new B();
Runnable t3 = new C();
bn.execute(t1);
bn.execute(t2);
bn.execute(t3);
bn.shutdwon();
}
}