Created
November 4, 2013 22:54
-
-
Save rei999/7310676 to your computer and use it in GitHub Desktop.
AsyncService Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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