Spring - Asynchronous longpooling rest controller via "callable"

June 14, 2016

Implementation of an controller with asyncronous processing. This is a good solution for whenever a long pooling is needed.

@RequestMapping(method = RequestMethod.PUT, path="xxx/yyy/{yyy}") 
public Callable<string> processProductImage2(HttpServletRequest request , @PathVariable("yyy") Integer yyy) { 
    Callable<string> callable = () -&gt; { 
        (...) // 
        long process (...) 
        return "ok"; 
    // return results to the caller return callable; 


  • Though the controller seams to return imidiatelly the caller connection will still remain opened untl the results are returned. That is, this solution is not an answer to an “fire-and-forget” controller