public static void main(String[] args) throws Exception{ RequestModel r = new RequestModel(); r.setTimestamp("123"); RequestModel model = new RequestModel(); model.setIdentityCard("310103198802264029"); model.setFamilyAddress("中国"); long start = System.currentTimeMillis(); try { int pagecount = 300; ExecutorService executors = Executors.newFixedThreadPool(pagecount); CountDownLatch countDownLatch = new CountDownLatch(pagecount); for (int i = 0; i < pagecount; i++) { String requestInfo = "<?xml version="1.0" encoding="UTF-8"?>"+ "<Agw direction="request"><Head><Trade>829401</Trade><App>000001</App><Channel>EAPCM</Channel>"+ "</Head><Body><field name="user_no">310103198802264029</field><field name="address">中国Demo+"+i+"</field>"+ "<field name="channel">01</field></Body></Agw>"; // 启动线程抓取 executors.execute(new GetRunnable(requestInfo, countDownLatch,i)); } countDownLatch.await(); executors.shutdown(); } catch (InterruptedException e) { e.printStackTrace(); } finally { System.out.println("线程" + Thread.currentThread().getName() + "," + System.currentTimeMillis() + ", 所有线程已完成,开始进入下一步!"); } long end = System.currentTimeMillis(); System.out.println("consume -> " + (end - start)); } static class GetRunnable implements Runnable { private CountDownLatch countDownLatch; private String requestInfo; private int cou; public GetRunnable(String requestInfo, CountDownLatch countDownLatch,int cou) { this.requestInfo = requestInfo; this.countDownLatch = countDownLatch; this.cou = cou; } @Override public void run() { try { try { System.out.println("++++++++++"+requestInfo+"+++++++++++"); System.out.println(sendSPDBData(requestInfo)); System.out.println("============"+cou+"============="); } catch (Exception e) { e.printStackTrace(); } } finally { countDownLatch.countDown(); } } }