賬單類具有與國家明智賬單相關的所有邏輯。它從數據庫中獲取結果,然後爲用戶開票。帳單類實現Runnable。我想根據國家參數並行執行結算,以便大量用戶(500萬+)非常快速地結算。現在需要數小時完成。ThreadPoolExecutor正在運行的應用程序
我想實現ThreadPoolExecutor執行Billing類,但很困惑如何?以下有什麼區別或者我做錯了什麼?請建議!區共有20個國家,但我在這裏粘貼僅5
//for 20 countries ThreadPoolExecutor (20,20,20.......)????
ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 5, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(10), new ThreadPoolExecutor.CallerRunsPolicy());
executor.execute(new Billing("UK"));
executor.execute(new Billing("USA"));
executor.execute(new Billing("Germany"));
executor.execute(new Billing("Spain"));
executor.execute(new Billing("Italy"));
OR
ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 5, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(10), new ThreadPoolExecutor.CallerRunsPolicy());
for(int i=0;i<5;i++) // for 20 countries i<20??
{
executor.execute(new Billing("UK"));
executor.execute(new Billing("USA"));
executor.execute(new Billing("Germany"));
executor.execute(new Billing("Spain"));
executor.execute(new Billing("Italy"));
}
while (! executor.isTerminated()) {
try{
executor.awaitTermination(100, TimeUnit.SECONDS);
}catch(InterruptedException iE)
{
iE.printStackTrace();
System.out.println("Executor Exception: "+ iE);
}
在此先感謝!
你只是詢問是否要使用'for'循環?你的意思並不完全清楚。 – 2013-02-27 16:17:47
@TimBender ...........我修改了我的問題... – 2013-02-27 16:25:58
@TimBender ..我很困惑在實施ThreadPoolExecutor執行Billing類..我該如何實現?我是否必須在ThreadPoolExecutor中使用For循環?或者它將並行運行所有計費類.. – 2013-02-27 16:28:23