@ApiOperation("test")
@PostMapping("test")
@ResponseBody
public String test() {
int count = 200;
String url = "http://localhost:8080/newrank/getNewRankCityInfo";
CountDownLatch latch = new CountDownLatch(count);
RankCityReq req = new RankCityReq();
req.setRankType(1);
for (int i = 0; i < count; i++) {
int finalI = i;
new Thread() {
@Override
public void run() {
try {
latch.await();
//在此处执行要调用的接口
String response = HttpRequestUtil.connect(url)
.header("Content-Type", "application/json")
.charset("utf-8")
.timeout(5000)
.json(JSON.toJSONString(req))
.post()
.html();
if (StringUtils.isNotBlank(response)) {
BaseResponse<NewRankCityInfoResp> newRankCityInfoRespBaseResponse = JSON.parseObject(response, new TypeReference<BaseResponse<NewRankCityInfoResp>>() {
});
System.out.println(JSON.toJSONString(newRankCityInfoRespBaseResponse) + "ok_" + finalI);
}
} catch (Exception e) {
}
}
}.start();//每循环一次,就启动一个新的线程
latch.countDown();//每启动一个新的线程,count--
}
return "ok";
}