/[projects]/miscJava/Test3/src/main/java/dk/thoerup/asyncsamples/Jsr236.java
ViewVC logotype

Annotation of /miscJava/Test3/src/main/java/dk/thoerup/asyncsamples/Jsr236.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2510 - (hide annotations) (download)
Fri Apr 24 12:32:32 2015 UTC (9 years, 1 month ago) by torben
File size: 1392 byte(s)
added jsr236 sample
1 torben 2510 /* Using the managedExecutorServcice (as in JSR236 / JEE7 )
2     *
3     * If your container (eg tomcat) doesnt support this you may revert to a standart ExecutorService
4     * https://martinsdeveloperworld.wordpress.com/2014/02/25/using-java-ees-managedexecutorservice-to-asynchronously-execute-transactions/
5     */
6    
7     package dk.thoerup.asyncsamples;
8    
9     import java.io.IOException;
10     import java.util.logging.Level;
11     import java.util.logging.Logger;
12    
13    
14     import javax.annotation.*;
15     import javax.enterprise.concurrent.*;
16    
17     import javax.servlet.annotation.*;
18     import javax.servlet.ServletException;
19     import javax.servlet.http.HttpServlet;
20     import javax.servlet.http.HttpServletRequest;
21     import javax.servlet.http.HttpServletResponse;
22    
23    
24    
25    
26    
27     @WebServlet( urlPatterns = "/Jsr236")
28     public class Jsr236 extends HttpServlet {
29     private static final long serialVersionUID = 1L;
30    
31     static final Logger logger = Logger.getLogger(WorkManagerSample.class.getName());
32    
33     @Resource
34     private ManagedExecutorService managedExecutorService;
35    
36    
37     class MyWork implements Runnable {
38    
39     @Override
40     public void run() {
41     DummyWork.doWork();
42     }
43    
44     }
45    
46    
47     @Override
48     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
49     managedExecutorService.submit( new MyWork() );
50    
51     response.getWriter().print("Finished");
52     }
53    
54    
55     }

  ViewVC Help
Powered by ViewVC 1.1.20