<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");
         }
     }
    主站蜘蛛池模板: 午夜毛片不卡高清免费| 一区二区免费视频| 国产午夜影视大全免费观看| 亚洲成人福利网站| 永久在线免费观看| 亚洲国产精品成人综合色在线婷婷| 国产好大好硬好爽免费不卡| 亚洲人成在线电影| 日韩插啊免费视频在线观看| 亚洲bt加勒比一区二区| 亚洲网站免费观看| 亚洲ts人妖网站| 免费无码不卡视频在线观看| 亚洲欧美综合精品成人导航| 免费永久看黄在线观看app| 羞羞漫画页面免费入口欢迎你| 亚洲AV无码乱码精品国产| 久久久精品国产亚洲成人满18免费网站| 亚洲国产精品无码久久九九| 91在线免费视频| 精品亚洲成a人片在线观看少妇| 在线精品一卡乱码免费| 久久精品国产亚洲av品善| 亚洲精品第一国产综合精品99| 国产在线观看xxxx免费| 亚洲成人在线网站| 少妇高潮太爽了在线观看免费| 亚洲爆乳AAA无码专区| 亚洲а∨天堂久久精品| 亚洲免费观看视频| 亚洲Av高清一区二区三区| 国产成人免费ā片在线观看 | 久久久久国色AV免费观看性色| 亚洲国产欧美一区二区三区| 亚洲偷自拍拍综合网| 免费精品无码AV片在线观看| 亚洲狠狠色丁香婷婷综合| 亚洲中文字幕无码永久在线| 国产免费丝袜调教视频| 一本久久免费视频| 亚洲国产视频一区|