zoukankan      html  css  js  c++  java
  • main方法并发测试

    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();
                    }
                }
            }
  • 相关阅读:
    POJ3297+map字符串处理
    POJ3204+DInic+maxflow
    HDU4704+费马小定理
    FZU-1924+判断环/DFS/BFS
    FZU-1921+线段树
    FZU-1926+KMP
    CodeForce 339:A+B+C
    HDU2896+AC自动机
    POJ2527+多项式除法
    鼠标移入移出事件
  • 原文地址:https://www.cnblogs.com/sprinng/p/5822584.html
Copyright © 2011-2022 走看看