我在jetty异步http客户端上运行以下程序。
Code is public static void main(String[] args) throws InterruptedException, TimeoutException, ExecutionException { String url2="http://www.google.co.in"; // JettyHttp.sendHttpSyncReq(url2); JettyHttp.sendHttpAsyncReq(url2); } public static void sendHttpAsyncReq(String url) throws InterruptedException, TimeoutException, ExecutionException { SslContextFactory sslContextFactory = new SslContextFactory(); HttpClient httpClient =new HttpClient(sslContextFactory); long total_t1=System.currentTimeMillis(); httpClient.newRequest(url).send(new Response.CompleteListener() { @Override public void onComplete(Result arg0) { // TODO Auto-generated method stub } }); long total_t2=System.currentTimeMillis(); System.out.println(total_t2-total_t1 +" =="); }
我得到的错误是
Exception in thread "main" java.util.concurrent.RejectedExecutionException: org.eclipse.jetty.client.HttpClient@412429c is stopped at org.eclipse.jetty.client.HttpDestination.send(HttpDestination.java:198) at org.eclipse.jetty.client.HttpClient.send(HttpClient.java:485) at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:486) at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:479) at com.nielsen.http.JettyHttp.sendHttpAsyncReq(JettyHttp.java:38) at com.nielsen.http.JettyHttp.main(JettyHttp.java:28)
请帮我解决这个错误::
答案 0 :(得分:1)
你忘了启动HttpClient。
SslContextFactory sslContextFactory = new SslContextFactory();
HttpClient httpClient =new HttpClient(sslContextFactory);
httpClient.start();
请注意,您的所有请求和关联只需要1 HttpClient
。 HttpClient
对象与浏览器具有相同的逻辑角色,可以管理多个连接选项卡。