Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-452

Specify that web scoped (request, session, application) beans are injectable in async servlets

XMLWordPrintable

      Consider this code based on this blog post: < https://weblogs.java.net/blog/swchan2/archive/2013/06/06/asynchronous-servlet-and-java-ee-concurrency-utilities >.

      @WebServlet(urlPatterns="/test2", asyncSupported=true)
      public class TestAsyncMESServlet extends HttpServlet {
          @Resource
          private ManagedExecutorService managedExecutorService;
      
          @Inject
          MyRunnableImpl myRunnableImpl;
      
          @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse res)
                  throws ServletException, IOException {
      
              final AsyncContext asyncContext = req.startAsync();
              final PrintWriter writer = res.getWriter();
      
              managedExecutorService.submit(myRunnableImpl);
          }
      
          public static class MyRunnableImpl implements Runnable {
      
            @Inject
            Bean bean; // Bean is @RequestScoped
      
            @Override
            public void run() {
      	  writer.println("Done");
      	  asyncContext.complete();
            }
      
          }
      }
      

      According to Jozef Hartzinger, this currently does not work, because only @Dependent and @ApplicationScoped beans are propagated to the new thread. To keep CDI relevant in light of the reactive programming movement and the popularity of node.js, we need to make this work.

              meetoblivion_jira John Ament (Inactive)
              edburns00 Edward Burns (Inactive)
              Votes:
              5 Vote for this issue
              Watchers:
              14 Start watching this issue

                Created:
                Updated:
                Resolved: