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

    Details

      Description

      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.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  meetoblivion John Ament
                  Reporter:
                  edburns Edward Burns
                • Votes:
                  5 Vote for this issue
                  Watchers:
                  13 Start watching this issue

                  Dates

                  • Created:
                    Updated: