Skip to content

Instantly share code, notes, and snippets.

@barron9
Last active September 13, 2021 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barron9/4e9f3bbf755c12fe289d6651bff1abd5 to your computer and use it in GitHub Desktop.
Save barron9/4e9f3bbf755c12fe289d6651bff1abd5 to your computer and use it in GitHub Desktop.
@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