I created a CallableDecorator for Runnable to fix this. Now I have proper return value even using GenericObjectPool. Since now there is no dependency on Pool object for reading status, even reusing of object does not leads to reset of status -
So, 2 changes in code - Change
futures.add(completionService.submit(myRunnable, myRunnable));
to
futures.add(completionService.submit(new CallableDecorator(myRunnable)));
add a new class
public class CallableDecorator implements Callable {
IRunnable r;
public CallableDecorator(IRunnable r) {
this.r = r;
}
public Integer call() {
r.run();
return r.statusCode();
}
}
interface IRunnable extends Runnable {
public Integer statusCode();
}
Similarly ,the resultObj must be changed to be integer for getting its value in the monitor thread.