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);//主線程等一下創建子線程 } }
模擬有個接口,不做具體實現了。