This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Now when the task completes I get a Future object and when I call get(), I always get 1 as the output as I have specified it while calling the Submit.
My requirement is that I want to return some other int like -1 when something wrong happens while executing the task.
How can I do this?
What do you mean by "something wrong happens"? A runnable throws no exceptions and returns no values... how do you expect the executor to detect this "something wrong happens"?
Anyway, think of the value returned as a token. It could be an array index, it could be a key to a hashmap, etc. You should use this token to get the result, so if "something wrong happens", you should store the result there. The token is not the result, but a way to get the result.