Sending web request and not waiting for response

2019-07-30 15:57发布

I am using this way of sending http get requests at the moment using HttpURLConnection. (http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/)

I was wondering how would I go about not receiving the response from the request or even acknowledge it at all and just needed the request to be fired off as fast as possible how could I achieve this?

Thanks.

1条回答
We Are One
2楼-- · 2019-07-30 16:22

What you need is a "fire and forget" semantic, not directly related to http request, rather more to threads. Simply launch whatever your task is, in a new thread

Thread thread = new Thread(new Runnable(){
  @Override
  public void run(){
    HttpURLConnectionExample http = new HttpURLConnectionExample();
    System.out.println("Testing 1 - Send Http GET request");
    http.sendGet();
  }
});
thread.start();
查看更多
登录 后发表回答