aspose file tools*
The moose likes Threads and Synchronization and the fly likes Getting return value using Callable and Future Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Getting return value using Callable and Future" Watch "Getting return value using Callable and Future" New topic
Author

Getting return value using Callable and Future

Sara Brown
Ranch Hand

Joined: Feb 22, 2012
Posts: 55
Operation.java



Main.java



My questions:
1- How to get the return value from the Operation.java? It gets error for future.get() which i really don't know what else should i put in the code.
2- Do i need executor.shutdown for this?
Sara Brown
Ranch Hand

Joined: Feb 22, 2012
Posts: 55
im wondering, why it works for future.get() when in try and catch method? and not works out in others?
Manish Sridharan
Ranch Hand

Joined: Jul 19, 2005
Posts: 64
future.get() method throws java.lang.InterruptedException, java.util.concurrent.ExecutionException which either you need to catch it or add throw for these exception in your main method.
I would suggest to have a look on Future Class APIs to understand its behaviour.
And yes, you need to add shutdown() to end the executor service otherwise it will continue to run indefinitely.


Thanks


Manish S.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting return value using Callable and Future