ETA: I'm genuinely baffled by the proposed solution, and I struggled to phrase my comment in a way that didn't come off as confrontational. So please accept my apologies if it still appears overly negative; it's entirely possible I've not understood what your goals and constraints are.
var input = new HashMap<Integer, String>();
var results = new ConcurrentHashMap<Integer, Document>();
var futures = input.entrySet().stream().map(entry ->
CompletableFuture.runAsync(() -> {
var sentiment = getSentiment(entry.getValue());
results.put(entry.getKey(), new Document(entry.getKey(), sentiment));
})
);
CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).join();
Let us know what the speedup is :)https://openjdk.java.net/jeps/8277131 https://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.... https://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part2.... https://youtu.be/KG24inClY2M
I'd wrap an executor into a provider. Make it accept a WorkItem and the method accepting WorkItem would construct the Callable.
I would suggest looking into an optimal way of doing this in, say, Scala and try to replicate some of those learnings in Java. Mind you - I didn't say "write it in Scala". I did say "try in a different language" and take the learnings from there. Scala Future is a good thing to look at.