0

I'm creating a mod that needs to call a GET request to an endpoint.
I don't care about any result, I just want the request to be sent.

Right now I'm using

HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);

And it will block. Because the api takes some time to respond that's not good.

I saw that there's a library called async-http-client but I can't add libraries to my project.

I guess I have to create threads in my mod but that doesn't look like the best solution to me as minecraft mods shouldn't make new threads.

Is there any java package that won't care about the response?

Tvde1
  • 1,076
  • 2
  • 16
  • 32

1 Answers1

0

Sending network traffic will always block until it's completed - there's no way around that. In this case it should be perfectly fine to create a new thread to do that actual work - the thread will just block (and not waste CPU resources) for most of the time.

Note that async-http-client will just create it's own threads to do it's work, so it won't help get around this restriction.

AlexIIL
  • 1
  • 2
  • I'm not certain about "will always block": as the "java.nio" package exists. Might https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java#921400 work instead? – AlexIIL Mar 06 '18 at 02:39