public class TestInvokeRemote{ //模拟200并发 private static final int MAX_REQUEST_COUNT=200;
//模拟有个接口 private static final String URL="http://xxx/xxx?xxx=xxx";
//模拟有个处理请求接口的类 ResultX x = new ResultX(); private static CountDownLatch cdl = new CountDownLatch(MAX_REQUEST_COUNT); @Test public void TestInvoke() throws Exception{ for(int=0; i<MAX_REQUEST_COUNT; i++){ Thread t=new Thread(()->{ cdl.countDown();//递减1 cdl.await();//等待
//模拟请求接口 String resultX=x.getEntity(URL).getBody(); system.out.print(resultX); }); t.start(); } Thread.sleep(3000);//主线程等一下创建子线程 } }
模拟有个接口,不做具体实现了。