I have a WEIRD problem with Future.get () in Java. It always returns with an InterruptedException, however it is strange that the cause of the exception is null, so I canโt say who interrupted me ..
This gets even worse, because I check before calling get (), and the work that Future should do is already done.
Below is the code responsible for the output below. f is the future , and the caller returns a HashMap, where the agent has no special meaning. Sorry if there are too many lines of print, I'm just trying to give as little information as possible. The call method from the called now is a simple System.out.println("Hola soy agente") which, as you will see, is printed, which means that the called did not raise an exception either
Here is the code:
try { System.out.println(f.isDone()); //true System.out.println(f.isCancelled()); //false System.out.println(f.toString()); //FutureTask newModdedAgents.putAll(f.get()); }catch(InterruptedException e) { System.out.println(f.isDone()); //true System.out.println(f.isCancelled()); //false System.err.println(e); //It is an interruptedException System.err.println(e.getCause()); //???? null? e.printStackTrace(); }
And exit
Hola soy agente true false java.util.concurrent.FutureTask@1c4c94e5 true false java.lang.InterruptedException null java.lang.InterruptedException at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1302) at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:248) at java.util.concurrent.FutureTask.get(FutureTask.java:111) at com.pf.simulator.Simulation.simulateStep(Simulation.java:217) at com.pf.gui.ButtonPanel.doWork(ButtonPanel.java:141) at com.pf.gui.ButtonPanel$1$1.construct(ButtonPanel.java:198) at com.pf.gui.SwingWorker$2.run(SwingWorker.java:117) at java.lang.Thread.run(Thread.java:636)
In case you want to see where I suppress the threadpool called thread ... then that would be the code for it
for(Callable<HashMap<Integer, Agent>> c : agentCallables) { Future<HashMap<Integer,Agent>> future = pool.submit(c); agentFutureSet.add(future); }
and after that I repeat this set with
for(Future<HashMap<Integer, Agent>> f : agentFutureSet) try {
source share