Java applet detects the concurrency of the web---httpclient and util packages concurrent

Source: Internet
Author: User

1. Download the Org.apache.commons.httpclient.jar file.

2. Use HttpClient to access the Web site (URL).

3. Use multithreading to test the number of concurrency. The Java.util.concurrent package implements concurrency.

The code is as follows:

1 Importjava.io.IOException;2 ImportJava.util.concurrent.ExecutorService;3 Importjava.util.concurrent.Executors;4 ImportJava.util.concurrent.TimeUnit;5 6 Importorg.apache.commons.httpclient.HttpClient;7 Importorg.apache.commons.httpclient.HttpException;8 ImportOrg.apache.commons.httpclient.HttpMethod;9 ImportOrg.apache.commons.httpclient.methods.GetMethod;Ten  One  A  -  -  Public classCeshi { the  -     /** -      * @paramargs -      * @throwsIOException +      * @throwsHttpException -      * @throwsinterruptedexception +      */ A      Public Static voidMain (string[] args)throwsHttpException, IOException, interruptedexception { atExecutorservice service=Executors.newfixedthreadpool (integer.max_value); -         inti = 0; -          for(i= 0; i < 4000; i++) { -System.out.println ("number" + (i+1) + "starts"); -Service.execute (NewRunnable () { - @Override in                  Public voidrun () { -                     Try { to Ceshi (); +}Catch(HttpException e) { -System.out.println ("HttpException"); the e.printstacktrace (); *}Catch(IOException e) { $System.out.println ("IOException");Panax Notoginseng e.printstacktrace (); -                     } the                 } +             }); ASystem.out.println ("number" + (i+1) + "ends"); the         } +           - Service.shutdown (); $          $           -Service.awaittermination (300, timeunit.seconds); -          theSystem.out.println ("OK"); - Wuyi     } the      -      Wu     Private Static voidCeshi ()throwsHttpException, ioexception{ -HttpClient client =NewHttpClient (); About  $Client.gethostconfiguration (). Sethost ("9.186.62.58", 8080, "http"); -  -HttpMethod method = Getgetmethod ();//submit data using Post -  A Client.executemethod (method); +  the         //status returned by the print server -  $ System.out.println (Method.getstatusline ()); the  the         //Print results page the  theString response =NewString (Method.getresponsebodyasstring (). GetBytes ("GB2312")); -  in         //Print the returned information the  the System.out.println (response); About  the method.releaseconnection (); the     } the      +     Private StaticHttpMethod Getgetmethod () { -  the         return NewGetMethod ("/bimaiapp/airdetailpage?cityids=1");Bayi  the         }  the  -}
View Code

Java applet detects the concurrency of the web---httpclient and util packages concurrent

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.