I'm having a hard time interating a HashMap<String, Future<DPSImporterServiceImpl>>
:
for (Entry<String, Future<DPSImporterServiceImpl>> entry : map.entrySet()) {
logger.debug("Thread: " + entry.getKey() + "/"
+ entry.getValue());
Future<DPSImporterServiceImpl> fut = entry.getValue();
try {
DPSImporterServiceImpl imp = fut.get();
logger.debug("Waiting over for: " + imp.toString());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
My map contains two entries: {1435748953925=java.util.concurrent.FutureTask@705f23aa, 1435748971395=java.util.concurrent.FutureTask@761ea788}
Here's my logger outcome:
Thread: 1435748953925/java.util.concurrent.FutureTask@705f23aa
Waiting over for: Thread busy with 1435748971395.
Thread: 1435748971395/java.util.concurrent.FutureTask@761ea788
Waiting over for: Thread busy with 1435748971395.
As you can see the map gets iterated correctly because the log statements starting with Thread...
are the ones from the map.
The get()
Method though does not work correctly as it is apparently getting called from the same object (both times from the second entry with the key 1435748971395
).
This is quite confusing to me as the map definitely doesn't contain identic objects.
Could you tell me what might be wrong here? Thank you!