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