Java implements the HttpClient asynchronous request resource Method _java

Source: Internet
Author: User

This article describes the Java implementation httpclient asynchronous request resources. Share to everyone for your reference. The implementation method is as follows:

Package demo;
Import Java.util.concurrent.CountDownLatch;
Import Org.apache.http.HttpResponse;
Import Org.apache.http.client.methods.HttpGet;
Import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
Import org.apache.http.nio.client.HttpAsyncClient;
Import Org.apache.http.nio.concurrent.FutureCallback;
Import org.apache.http.nio.reactor.IOReactorException; public class Main {/** * @param args * @throws ioreactorexception * @throws interruptedexception/Public St atic void Main (string[] args) throws Ioreactorexception, interruptedexception {final httpasyncclient httpclient = new D
  Efaulthttpasyncclient ();
  Httpclient.start (); Httpget[] Requests = new httpget[] {new HttpGet ("http://www.apache.org/"), New HttpGet ("https://www.verisign.com/
  "), New HttpGet (" http://www.google.com/")};
  Final Countdownlatch latch = new Countdownlatch (requests.length); try {for (final httpget request:requests) {httpclient.execute (Request, new FuturecallbacK 

I hope this article will help you with your Java programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.