账单类具有与国家明智账单相关的所有逻辑。它从数据库中获取结果,然后为用户开票。帐单类实现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