]
Romain Manni-Bucau commented on CDI-452:
----------------------------------------
+1, also note that not propagating the main context makes it pretty useless. Takes a
simple and very common use case where you have a security filter pushing data in a request
scoped bean (display name, login etc...) and a @Suspended jaxrs endpoint then no way to
get the filter data. This is not only about EE concurrency but a way to let user propagate
properly a context - then thread safety etc is up to him. So we need a cdiWhatever =
enterContext(scope); ....; exitContext(cdiWhatever);
There are really no technical blocker for that and would make context far more powerful in
nowadays world using more and more such a things.
Specify that web scoped (request, session, application) beans are
injectable in async servlets
----------------------------------------------------------------------------------------------
Key: CDI-452
URL:
https://issues.jboss.org/browse/CDI-452
Project: CDI Specification Issues
Issue Type: Feature Request
Components: Contexts, Java EE integration
Affects Versions: 1.0
Reporter: Ed Burns
Assignee: John Ament
Fix For: 2.0 (discussion)
Consider this code based on this blog post: <
https://weblogs.java.net/blog/swchan2/archive/2013/06/06/asynchronous-ser...
>.
{code}
@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();
}
}
}
{code}
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.