Acid_
Acid_

Reputation: 15

Sending web request and not waiting for response

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.

Upvotes: 1

Views: 2299

Answers (1)

Master Slave
Master Slave

Reputation: 28519

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();

Upvotes: 1

Related Questions