Last active
August 29, 2015 14:12
-
-
Save maxant/86e5710da8e268f1bcf0 to your computer and use it in GitHub Desktop.
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
package ch.maxant.async; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.concurrent.Future; | |
import javax.ejb.EJB; | |
import javax.servlet.ServletException; | |
import javax.servlet.annotation.WebServlet; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
@WebServlet(urlPatterns = { "/AsyncServlet" }) | |
public class AsyncServlet extends HttpServlet { | |
private static final long serialVersionUID = 1L; | |
@EJB | |
private Service1 service; | |
protected void doGet(HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { | |
PrintWriter pw = response.getWriter(); | |
pw.write("<html><body>Started publishing with thread " + Thread.currentThread().getId() + "<br>"); | |
try { | |
Future<String> s = service.foo(); | |
pw.write("service response is:"); | |
pw.write(s.get()); // blocks :-( | |
pw.write("</body></html>"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment