By using ExecutorService we can create a pool of threads and run in parallel. This feature has introduced in JAVA5.
see the below links.
ExecutorService
ThreadPoolExecutor
here is an example:
ExecutorService exec = Executors.newFixedThreadPool(10);
for (int i=0;i<100;i++) {
exec.execute(new DoSomething(data));
}
in this example we have created a pool of threads contains 10. Here new DoSomething(data) will be executed 10times parallel.
this can be used, where we need to call Web services since we cannot create webservice connection pool.
see the below links.
ExecutorService
ThreadPoolExecutor
here is an example:
ExecutorService exec = Executors.newFixedThreadPool(10);
for (int i=0;i<100;i++) {
exec.execute(new DoSomething(data));
}
in this example we have created a pool of threads contains 10. Here new DoSomething(data) will be executed 10times parallel.
this can be used, where we need to call Web services since we cannot create webservice connection pool.
Comments
Post a Comment