title: RESTEasy + Asynchronous + Callback Method + Java
body: <p>I want to support both Synchronous and Asynchronous call using RESTEasy-JAXRS. And my asynchronous call should be based on callback, where Async request will have callbackURI, request gets processed asynchronously and upon completion makes a call to callbackURI with operation status/result. Can someone point me out to correct place? I see lot about polling model, but not callback with RESTEasy.</p>
  
  <p>I am new to Asynchronous stuff...</p>
  
  <p>Thanks in advance!</p>
  
  <p>Thanks for your response rmlan.Yes but we have support in JAX-RS to handle asynchronous using @Suspended &amp; AsyncResponse. I did that with following code, but i am unable to find the way to make callback to Client who called the API upon completion of task with this request.                                                         </p>
  
  <pre><code>@GET
  @Path("/async")
  public String checkAsync(@Suspended final AsyncResponse response) {
      response.setTimeoutHandler(new TimeoutHandler() {
  
          @Override
          public void handleTimeout(AsyncResponse asyncResponse) {
              response.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE)
                      .entity("Operation time out.").build());
          }
      });
      response.setTimeout(2, TimeUnit.SECONDS);
  
      new Thread(new Runnable() {
              @Override
              public void run() {
                  String result = veryExpensiveOperation();
                  response.resume(result);
              }
  
              private String veryExpensiveOperation() {
                  try {
                      Thread.sleep(5000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
                  logger.debug("Task is processed fully");
                  return "Successful";
              }
          }).start();
  
      return "nothing";
  }
  </code></pre>