Skip to content

Instantly share code, notes, and snippets.

View tomfitzhenry's full-sized avatar

tomf tomfitzhenry

View GitHub Profile
@tomfitzhenry
tomfitzhenry / MakeTwoDnsRequests.java
Last active March 6, 2018 09:56
OpenJDK bug: Enabling JMX silently causes the disabling of the JVM's DNS cache to not work
import java.security.Security;
import java.net.InetAddress;
public class MakeTwoDnsRequests {
public static void main(String[] args) throws Exception {
// Disable JVM DNS caching
Security.setProperty("networkaddress.cache.ttl", "0");
System.out.println(InetAddress.getByName("www.example.com").getHostAddress());
@tomfitzhenry
tomfitzhenry / CompletableHttpAsyncClient.java
Last active August 17, 2021 13:04
CompletableHttpAsyncClient: Adaptor for HttpAsyncClient + Java 8
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.nio.client.HttpAsyncClient;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.protocol.HttpContext;