Questions tagged [callable]

A task that returns a result and may throw an exception.

The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.

655 questions
518
votes
14 answers

The difference between the Runnable and Callable interfaces in Java

What is the difference between using the Runnable and Callable interfaces when designing a concurrent thread in Java, why would you choose one over the other?
Scottm
  • 6,381
  • 6
  • 30
  • 32
333
votes
12 answers

What is a "callable"?

Now that it's clear what a metaclass is, there is an associated concept that I use all the time without knowing what it really means. I suppose everybody made once a mistake with parenthesis, resulting in an "object is not callable" exception.…
e-satis
  • 515,820
  • 103
  • 283
  • 322
63
votes
9 answers

TypeError: 'list' object is not callable while trying to access a list

I am trying to run this code where I have a list of lists. I need to add to inner lists, but I get the error TypeError: 'list' object is not callable. Can anyone tell me what am I doing wrong here. def createlists(): global maxchar global…
user487257
  • 961
  • 2
  • 7
  • 16
60
votes
3 answers

How to use Callable with void return type?

I am working on a project in which I have multiple interface and two Implementations classes which needs to implement these two interfaces. Suppose my first Interface is - public Interface interfaceA { public void abc() throws Exception; } And…
AKIWEB
  • 16,538
  • 58
  • 164
  • 276
52
votes
6 answers

What's the difference between Future and FutureTask in Java?

Since use ExecutorService can submit a Callable task and return a Future, why need to use FutureTask to wrap Callable task and use the method execute? I feel they both do the same thing.
Hesey
  • 4,307
  • 5
  • 28
  • 31
47
votes
8 answers

Is there a way to take an argument in a callable method?

I have created a piece of code which takes an IP address (from main method in another class) and then loops through a range of IP addresses pinging each one as it goes. I have a GUI front end on this and it was crashing (hence why I've done the…
DMo
  • 551
  • 1
  • 6
  • 13
28
votes
5 answers

Odd method call in java using a dot operator to access a generic list

I came across some advanced java code (advanced for me :) ) I need help understanding. In a class there is a nested class as below: private final class CoverageCRUDaoCallable implements Callable> { private final…
Horse Voice
  • 7,218
  • 14
  • 56
  • 111
28
votes
2 answers

When to use Spring @Async vs Callable controller (async controller, servlet 3)

I would like to know the general use case of using @Async and Servlet 3 asynchronous request implementation in Spring using Callable. As I understand, @Async is for making any method (specifically, any service method) execute…
devThoughts
  • 770
  • 1
  • 10
  • 16
26
votes
3 answers

Difference between Spring MVC's @Async, DeferredResult and Callable

I've a long-running task defined in a Spring service. It is started by a Spring MVC controller. I want to start the service and return back an HttpResponse to the caller before the service ends. The service saves a file on file system at end. In…
Premier
  • 3,952
  • 6
  • 39
  • 56
25
votes
1 answer

Where to catch Exceptions thrown from Callable.call()

Possible Duplicate: Handling exceptions from Java ExecutorService tasks I use the ExecutorService from Java for coordinating Threads. For starting the threads I use pool = new ExecutorService(2); callableResults = pool.invokeAll(threads); To…
nano7
  • 2,395
  • 6
  • 33
  • 51
23
votes
7 answers

What is a callable object in C++?

I'm currently studying boost threads. And I came across that the thread class has a constructor that accepts callable objects. What are callable objects? class CallableClass { private: // Number of iterations int m_iterations; public: …
Xegara
  • 443
  • 2
  • 9
  • 21
20
votes
1 answer

What is the difference between a function object and a callable object?

I recently saw the presentation about the changes in ECMAScript 5. And there was a slide with this statement: Function vs Callable typeof f === 'function' // → f is Callable ({}).toString.call(f) === '[object Function]' // → f…
Gumbo
  • 594,236
  • 102
  • 740
  • 814
20
votes
3 answers

How to pass a parameter to Scikit-Learn Keras model function

I have the following code, using Keras Scikit-Learn Wrapper, which work fine: from keras.models import Sequential from keras.layers import Dense from sklearn import datasets from keras.wrappers.scikit_learn import KerasClassifier from…
neversaint
  • 50,277
  • 118
  • 274
  • 437
19
votes
4 answers

RestTemplate should be static globally declared?

I am using Java Callable Future in my code. Below is my main code which uses the future and callables - public class TimeoutThread { public static void main(String[] args) throws Exception { ExecutorService executor =…
AKIWEB
  • 16,538
  • 58
  • 164
  • 276
19
votes
6 answers

Java: Parameterized Runnable

Standard Runnable interface has only non-parametrized run() method. There is also Callable interface with call() method returning result of generic type. I need to pass generic parameter, something like this: interface MyRunnable { public…
mschayna
  • 1,270
  • 2
  • 14
  • 32
1
2 3
43 44