Search code examples
javajerseyjersey-client

Jersey client don't wait for result of GET method


I have a simple app in Java, using Jersey for the requests, where I hit some endpoints in other application using a GET request with Jersey like this:

Client client = new Client();
WebResource webResource = client.resource("MY_ENDPOINT");
webResource.get(String.class);

As you can see, I don't even care about the result of the endpoint, I just want to 'trigger' it, as the endpoint, once it receives a call, it will run some code on its own.

My 'issue' here is that I do this operation for 5 endpoints, and they usually take up to 3 seconds, and I don't need to wait that much, as the endpoint only returns an 'OK' message and I don't care about the actual message.

Is there any way to do this GET operation without 'blocking' Java? As in "do this call and ignore the result"? I would like to keep it with Jersey but I'm open to other ways.


Solution

  • I just moved to OkHttp:

        Request request = new Request.Builder().url(MY_ENDPOINT).build();
        client.newCall(request).enqueue(callback);
    

    and the callback variable is just an empty Callback.