Improve your WEBServices Consumer Apps Making WS Invocations in Parallel


If your application is calling several WS and there is no need to do it in serial, you can implement a multithreaded approach:

calling ws in parallel

Example:

Class1Service class1Service = new Class1Service();

        x = class1Service.getClass1Port();

        setWSTimeout(x); // esto lo veremos en la siguiente seccion

        class Task implements Callable<Object> {

             private Object result;

             public Object call() {

                  // compute result

                  try{

                      x.getCosa();  

                  }

                  catch (Exception e){

                      e.printStackTrace(System.out);

                  }

                  return result;

             }

        }

        Task c1 = new Task();

        Task c2 = new Task();

        ExecutorService exec = Executors.newFixedThreadPool(2);

        Future<Object> f1 = exec.submit(c1);

        Future<Object> f2 = exec.submit(c2);

        try{

            f1.get();

            f2.get();

        }

        catch(Exception e){

            e.printStackTrace(System.out);

        }

Enjoy 😉

Sin categoría

javier mugueta View All →

Me and my circumstance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: