Last active
September 13, 2021 15:03
-
-
Save barron9/4e9f3bbf755c12fe289d6651bff1abd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
class HTTPClient{ | |
private HttpRequest request; | |
private HttpClient client; | |
private LoggerM logger; | |
@Inject | |
HTTPClient(LoggerM logger) { | |
ExecutorService ex = Executors.newFixedThreadPool(2); | |
System.out.println(Thread.currentThread().getName()); | |
client = HttpClient.newBuilder().executor(ex).build(); | |
try { | |
request = HttpRequest.newBuilder() | |
.uri(new URI("https://fakestoreapi.com/products/1")) | |
.GET().build(); | |
} catch (Exception h) { | |
System.err.println(h.getMessage()); | |
} | |
} | |
public CompletableFuture<HttpResponse<String>> get() throws IOException, InterruptedException { | |
Thread.sleep(5234); | |
return client.sendAsync(request, HttpResponse.BodyHandlers.ofString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment