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

Your controller is eventually a function executed by the servlet container (I will assume it is Tomcat) worker thread. Your service flow start with Tomcat and ends with Tomcat. Tomcat gets the request from the client, holds the connection, and eventually returns a response to the client. Your code (controller or servlet) is somewhere in … Read more

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

You can’t pass it as the argument to call() because the method signature doesn’t allow it. However, you can pass the necessary information as a constructor argument; e.g. public class DoPing implements Callable<String>{ private final String ipToPing; public DoPing(String ipToPing) { this.ipToPing = ipToPing; } public String call() throws SomeException { InetAddress ipAddress = InetAddress.getByName(ipToPing); … Read more

How to use Callable with void return type?

You can use java.lang.Thread for parallel execution. However, in most cases it’s easier to use an java.util.concurrent.ExecutorService. The latter provides a method to submit a Callable and returns a Future to get the result later (or wait for completion). If testA.abc() and testB.xyz() should be executed in parallel, you use the ExecutorService to execute the … Read more

What is a “callable”?

A callable is anything that can be called. The built-in callable (PyCallable_Check in objects.c) checks if the argument is either: an instance of a class with a __call__ method or is of a type that has a non null tp_call (c struct) member which indicates callability otherwise (such as in functions, methods etc.) The method … Read more