Skip to content

Instantly share code, notes, and snippets.

@rei999
Created November 4, 2013 22:54
Show Gist options
  • Save rei999/7310676 to your computer and use it in GitHub Desktop.
Save rei999/7310676 to your computer and use it in GitHub Desktop.
AsyncService Example
public interface MyService {
Future<String> testAsync();
}
@Service
@Transactional
public class MyServiceImpl implements MyService {
@Async
@Override
public Future<String> testAsync() {
String hello = "world";
String threadName = Thread.currentThread().getName();
System.out.println(" " + threadName + " beginning work");
try {
Thread.sleep(10000); // simulates work
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
System.out.println(" " + threadName + " completed work");
return new AsyncResult<String>(hello);
}
}
public interface MyApiService {
String testAsync() throws Exception;
}
@Path("/api")
@Service("srvMyApi")
public class MyApiServiceImpt implements MyApiService {
@Override
@GET
@Path("/testAsync")
@Produces(MediaType.APPLICATION_JSON)
public String testAsync() throws Exception {
Future<String> future = bookService.testAsync();
HttpServletRequest req = context.getHttpServletRequest();
return "called Async";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment