Cha*_*ase 16 java multithreading executorservice threadpool
在Java程序中使用Executors而不仅仅是Threads有什么好处.
如
ExecutorService pool = Executors.newFixedThreadPool(2);
void someMethod() {
//Thread
new Thread(new SomeRunnable()).start();
//vs
//Executor
pool.execute(new SomeRunnable());
}
Run Code Online (Sandbox Code Playgroud)
执行程序是否仅限制允许一次运行的线程数(线程池)?它是否实际上将runnable复用到它创建的线程上?如果不是,它只是一种避免每次都必须编写新的Thread(runnable).start()的方法吗?