<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
    View Code
     package generate.httpclient;
     
     import java.io.ByteArrayOutputStream;
     import java.io.IOException;
     import java.io.InputStream;
     import java.util.ArrayList;
     import java.util.HashMap;
     import java.util.List;
     import java.util.Map;
     import java.util.concurrent.CountDownLatch;
     
     import org.apache.http.HttpResponse;
     import org.apache.http.client.methods.HttpGet;
     import org.apache.http.concurrent.FutureCallback;
     import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
     import org.apache.http.nio.client.HttpAsyncClient;
     import org.apache.http.nio.reactor.IOReactorException;
     
     public class AsynClient{
         /**
          * @param args
          * @throws IOReactorException
          * @throws InterruptedException
          */
         private List<String> urls;
         private HandlerFailThread failHandler;
         public AsynClient(List<String> list){
             failHandler=new HandlerFailThread();
             urls=list;
         }
         public Map<String,String> asynGet() throws IOReactorException,
                 InterruptedException {
             final HttpAsyncClient httpclient = new DefaultHttpAsyncClient();
             httpclient.start();
             int urlLength=urls.size();
             HttpGet[] requests = new HttpGet[urlLength];
             int i=0;
             for(String url : urls){
                 requests[i]=new HttpGet(url);
                 i++;
             }
             final CountDownLatch latch = new CountDownLatch(requests.length);
             final Map<String, String> responseMap=new HashMap<String, String>();
             try {
                 for (final HttpGet request : requests) {
                     httpclient.execute(request, new FutureCallback<HttpResponse>() {
     
                         public void completed(final HttpResponse response) {
                             latch.countDown();
                             responseMap.put(request.getURI().toString(), response.getStatusLine().toString());
                             try {
                                 System.out.println(request.getRequestLine() + "->"
                                         + response.getStatusLine()+"->");
                                 //+readInputStream(response.getEntity().getContent())
                                
                             } catch (IllegalStateException e) {
                                 failHandler.putFailUrl(request.getURI().toString(),
                                         response.getStatusLine().toString());
                                 e.printStackTrace();
                             } catch (Exception e) {
                                 failHandler.putFailUrl(request.getURI().toString(),
                                         response.getStatusLine().toString());
                                 e.printStackTrace();
                             }
                         }
     
                         public void failed(final Exception ex) {
                             latch.countDown();
                             ex.printStackTrace();
                             failHandler.putFailUrl(request.getURI().toString(),
                                     ex.getMessage());
                         }
     
                         public void cancelled() {
                             latch.countDown();
                         }
     
                     });
                 }
                 System.out.println("Doing...");
             } finally {
                 latch.await();
                 httpclient.shutdown();
             }
             System.out.println("Done");
             failHandler.printFailUrl();
             return responseMap;
         }
         private String readInputStream(InputStream input) throws IOException{
             byte[] buffer = new byte[128];
             int len = 0;
             ByteArrayOutputStream bytes = new ByteArrayOutputStream();
             while((len = input.read(buffer)) >= 0) {
                 bytes.write(buffer, 0, len);
             }
             return bytes.toString();
         }
         /**
          * Test
          * @param args
          */
         public static void main(String[] args) {
             List<String> urls=new ArrayList<String>();
             urls.add("         urls.add("         urls.add("         for(int i=0;i<10;i++){
                 urls.addAll(urls);
             }
             System.out.println(urls.size());
             AsynClient client=new AsynClient(urls);
             try {
                 client.asynGet();
             } catch (IOReactorException e) {
                 e.printStackTrace();
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
             System.out.println("done");
         }
     }
    主站蜘蛛池模板: 永久免费观看的毛片的网站| 亚洲最大的成人网站| 亚洲 无码 在线 专区| 一区二区三区精品高清视频免费在线播放| 美女露100%胸无遮挡免费观看| 久久久精品免费国产四虎| 亚洲乱码中文字幕久久孕妇黑人 | 2022免费国产精品福利在线| 免费人成视频在线观看不卡| 青青草国产免费国产是公开| 亚洲国产主播精品极品网红| 国产精品青草视频免费播放| 亚洲婷婷五月综合狠狠爱| 国产精品免费一区二区三区四区| 亚洲今日精彩视频| 性短视频在线观看免费不卡流畅| 亚洲一区在线观看视频| 好男人视频在线观看免费看片| 久久久久久亚洲精品影院| 国产国产人免费人成免费视频| 免费手机在线看片| 亚洲第一极品精品无码久久| 24小时日本韩国高清免费| 2019亚洲午夜无码天堂| 又色又污又黄无遮挡的免费视 | 亚洲免费在线视频| 在线v片免费观看视频| 久久精品熟女亚洲av麻豆| 中文字幕在线亚洲精品| 最近中文字幕完整免费视频ww| 亚洲中文字幕无码av| 亚洲免费一区二区| 99在线观看免费视频| 亚洲精品无AMM毛片| 精品国产亚洲男女在线线电影| 免费国产黄网站在线观看视频| 亚洲爆乳少妇无码激情| 亚洲狠狠婷婷综合久久久久| 一本无码人妻在中文字幕免费 | 1a级毛片免费观看| 羞羞漫画在线成人漫画阅读免费|