• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Callable/Future Real world Example

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am learning java concurrent package these days. Today i learned about the Callable interface ,Future/FutureTask, Executor Service. I understood what these are and how to use them.

But I would like to know a real life example for the Callable interface as i have mostly used Runnable in my projects.


Has anyone used Callable in their project . Please throw some light here.

Thanks
Anuj
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

anuj guptaa wrote:But I would like to know a real life example for the Callable interface as i have mostly used Runnable in my projects.

A Callable is just like a Runnable, except it returns a value. It is used to provide a simple, Runnable-like API to insert your executable code into FutureTasks, where some return value is expected. Internally, FutureTask probably makes use of Runnable to execute the code, but in addition, will do something with the results (such as notify get()ers that it is ready).

Real-world use would be any long task that produces a result - get something from a database and turn it into an Object, make a long calculation with a result, query a web application, get some data, do something with that data, generate output...
 
anuj guptaa
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve!! Hope i will soon get a chance to use callable in my project..
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is an example of using Callable with a Thread Pool in this FAQ
 
anuj guptaa
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jayesh!! This link is quiet helpful !!
reply
    Bookmark Topic Watch Topic
  • New Topic