I'm stuck when using Java's CompletableFuture with JMS (ActiveMQ). When I send a request for which I expect a reply, I create a CompletableFuture and put that in a Map with the correlation ID as key.
This works perfectly as long as I get a reply. When I don't get a reply, zombie start to pile up in the map.
I tried to attach cleanup code to CompletableFuture using whenComplete() but the code isn't called at all when CompletableFuture.get(long,TimeUnit) times out (the Java code in timedGet() will just throw the exception without calling anything else).
This looks like such an obvious place to use the Future API. Does someone have a working example or an idea how to clean up dead entries in the map?
Note: It can take up to three hours until the response arrives.
Note 2: Java 8