讀書筆記:排序的執行器
package v1ch14.ThreadPoolTest;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* @version 2010-10-18 下午05:11:11
* @author DaWei han
* @EMAIL handawei_1@126.com
*/
public class MyPoolTest {
/**
* @param args
* @throws ExecutionException
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException, ExecutionException {
//構造一個執行緒池
ExecutorService executor=Executors.newCachedThreadPool();
//構造一個順序的執行器
ExecutorCompletionService<Integer> service=new ExecutorCompletionService<Integer>(executor);
List<Callable<Integer>> taks=getTasks();
for(Callable<Integer> call:taks)
{
//執行任務
service.submit(call);
}
for(int i=0;i<taks.size();i++)
{
//獲得任務結果。它們是按結果的快慢排序的。
service.take().get();
}
//上面的執行緒池順序服務是為了優化下面的執行緒池服務,因為下面的第一個任務可能很耗時,那麼後面的就必須等待。
List<Future<Integer>> results= executor.invokeAll(taks);
for(Future<Integer> result:results)
{
result.get();
}
}
public static List<Callable<Integer>> getTasks()
{
return null;
}
}
相關文章
- 【讀書筆記】Postgresql連線方法及執行器筆記SQL
- 《高效能JavaScript》讀書筆記①載入和執行JavaScript筆記
- 執行緒間協作-《thinking in java》讀書筆記(一)執行緒ThinkingJava筆記
- 讀書筆記筆記
- 讀書筆記...筆記
- 《CLR Via C#》讀書筆記:26.執行緒基礎C#筆記執行緒
- Cucumber讀書筆記筆記
- 散文讀書筆記筆記
- HTTP 讀書筆記HTTP筆記
- CoreJava讀書筆記-------Java筆記
- flask讀書筆記Flask筆記
- Vue讀書筆記Vue筆記
- MONGODB 讀書筆記MongoDB筆記
- Qt讀書筆記QT筆記
- Node讀書筆記筆記
- SAP讀書筆記筆記
- YII讀書筆記筆記
- iptables 讀書筆記筆記
- Makefile 讀書筆記筆記
- mysql讀書筆記MySql筆記
- 鎖讀書筆記筆記
- dataguard讀書筆記筆記
- 《CLR Via C#》讀書筆記:24.執行時序列化C#筆記
- 菜鳥的讀書筆記筆記
- 機器學習讀書筆記:貝葉斯分類器機器學習筆記
- 『TensorFlow』讀書筆記_降噪自編碼器筆記
- 《重構》讀書筆記筆記
- webpackDemo讀書筆記Web筆記
- PMBook讀書筆記(一)筆記
- Effective Java 讀書筆記Java筆記
- js高程讀書筆記JS筆記
- “Docker Practice”讀書筆記Docker筆記
- FPGA讀書筆記5FPGA筆記
- FPGA讀書筆記3FPGA筆記
- FPGA讀書筆記4FPGA筆記
- FPGA讀書筆記2FPGA筆記
- FPGA讀書筆記1FPGA筆記
- 《精通JavaScript》讀書筆記JavaScript筆記