threadpool

Thread vs ThreadPool

霸气de小男生 提交于 2019-11-25 23:46:07
问题 What is the difference between using a new thread and using a thread from the thread pool? What performance benefits are there and why should I consider using a thread from the pool rather than one I\'ve explicitly created? I\'m thinking specifically of .NET here, but general examples are fine. 回答1: Thread pool will provide benefits for frequent and relatively short operations by Reusing threads that have already been created instead of creating new ones (an expensive process) Throttling the

ExecutorService, how to wait for all tasks to finish

冷暖自知 提交于 2019-11-25 23:45:50
问题 What is the simplest way to to wait for all tasks of ExecutorService to finish? My task is primarily computational, so I just want to run a large number of jobs - one on each core. Right now my setup looks like this: ExecutorService es = Executors.newFixedThreadPool(2); for (DataTable singleTable : uniquePhrases) { es.execute(new ComputeDTask(singleTable)); } try{ es.wait(); } catch (InterruptedException e){ e.printStackTrace(); } ComputeDTask implements runnable. This appears to execute the