Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] how to shut down jetty httpclient (version 9.1)

Your code example attempts to stop the client from within a client thread.
Don't do that.

client.stop() should be called from outside of the client threads.

Typically, you start 1 HttpClient for the lifetime of the application, then just continue to reuse it for multiple requests / connections. only stopping it when your application is being shutdown.


--
Joakim Erdfelt <joakim@xxxxxxxxxxx>
Expert advice, services and support from from the Jetty & CometD experts


On Tue, Nov 26, 2013 at 3:54 AM, Kiwi de coder <kiwionly@xxxxxxxxx> wrote:
I had run the test again, now the client.stop is working for code above. (not sure what wrong previously, maybe my mistake). However, code for async :

                final HttpClient client = new HttpClient();
client.start();
client.newRequest("http://www.google.com").send(new BufferingResponseListener() {
@Override
public void onComplete(Result result) {
System.out.println(getContentAsString());
try {
client.stop();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});


look like when called client.stop(), it show this exception after a while (few seconds), to terminate the thread.


2013-11-26 18:46:26.688:WARN:oejuc.AbstractLifeCycle:HttpClient@1998356146-10: FAILED HttpClient@1998356146{FAILED,8<=1<=200,i=0,q=0}: java.lang.InterruptedException
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.Thread.join(Unknown Source)
at org.eclipse.jetty.util.thread.QueuedThreadPool.doStop(QueuedThreadPool.java:153)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:128)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:147)
at org.eclipse.jetty.client.HttpClient.doStop(HttpClient.java:245)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
at com.http.HttpClientTest$1.onComplete(HttpClientTest.java:27)
at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:213)
at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:205)
at org.eclipse.jetty.client.HttpReceiver.responseSuccess(HttpReceiver.java:350)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.messageComplete(HttpReceiverOverHTTP.java:196)
at org.eclipse.jetty.http.HttpParser.parseContent(HttpParser.java:1410)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1233)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.parse(HttpReceiverOverHTTP.java:116)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:82)
at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:75)
at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:109)
at org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:505)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
at java.lang.Thread.run(Unknown Source)


not sure is this correct way to close async call ?

kiwi







_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



Back to the top