If your application is calling several WS and there is no need to do it in serial, you can implement a multithreaded approach:
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 😉