i have following class where spring create object for the class. i have created WebClient to make http request using CXF. i want to make 2 http call which i want to execute in 2 thread so that, i dont have to call the method twice .
@Service
public class SalesManServiceWebClient {
@Value("${vehicle.api.url}")
private String vehicleUrl;
@Value("${customer.api.url}")
private String customerUrl;
private static final Logger LOG = LoggerFactory.getLogger(SalesManServiceWebClient.class);
public List<String> getListOfDmsId(String market,STouchServiceEnum stouchService)
{
List<String> dmsIdList= new ArrayList<>();
LOG.info("---Entering getListOfDmsId webClientService---");
LOG.info("customerUrl:"+customerUrl);
final String url = getServiceUrl(stouchService);
final List<Object> providers = new ArrayList<Object>();
providers.add(new JacksonJsonProvider());
//i want this to be execute in thread
CustomerServiceProxy proxy = JAXRSClientFactory.create(url, CustomerServiceProxy.class, providers);
Client client = WebClient.client(proxy);
client.type(MediaType.APPLICATION_JSON);
//client.accept(MediaType.APPLICATION_JSON);
client.header("ST_USER", "gasid3");
client.header("Content-Type", MediaType.APPLICATION_JSON_TYPE);
LOG.info("== Invoking REST Call for service ==" + url);
//till this
//i want this to be execute in thread
VehicleServiceProxy proxy = JAXRSClientFactory.create(url, VehicleServiceProxy.class, providers);
Client client = WebClient.client(proxy);
client.type(MediaType.APPLICATION_JSON);
//client.accept(MediaType.APPLICATION_JSON);
client.header("ST_USER", "gasid3");
client.header("Content-Type", MediaType.APPLICATION_JSON_TYPE);
LOG.info("== Invoking REST Call for service ==" + url);
//till this
/*Set<String> UniqueDmsId = new HashSet<>(dmsIdList);
dmsIdList.clear();
dmsIdList.addAll(UniqueDmsId);*/
return dmsIdList;
}
private String getServiceUrl(STouchServiceEnum stouchService)
{
String url="";
switch(stouchService)
{
case CUSTOMER:
//url="http://BLRKEC327951D:8080/stouch-admin-services/api";
url=customerUrl;
//url=customerUrl.concat("/User/dmsMap");
break;
case VEHICLE:
url=vehicleUrl.concat("/User/dmsMap");;
break;
default:
break;
}
return url;
}
}
In above code i want CustomerServiceProxy to be executed in one thread then vehicleServiceProxy in another and i want to aggregate the result once the two threads execution got completed.
can somebody help me on this?