[weld-dev] CDI + RequestScoped + thread safety

Stuart Douglas stuart.w.douglas at gmail.com
Sun May 4 13:00:48 EDT 2014


This is not the correct mailing list for these questions, this list is 
for discussing the development of weld. User questions should be asked 
on the weld forums.

What actually gets injected into your servlet is a proxy, and the proxy 
is thread safe. When a thread calls a method on the proxy Weld looks up 
the appropriate request scoped instance, and then delegates the 
invocation to that instance. If two threads are invoking on the same 
proxy it does not matter, as the underlying instances that the proxy 
delegates to will be different.


Stuart

Daniel Pub wrote:
> Hi all,
>
> I've been developing some code with CDI.
>
> I was wondering what happens when I mark a servlet property with @Inject
> and define the bean with @RequestScoped but the bean class itself is not
> thread safe but it's a property of my servlet so looking by the servlet
> perspective it could be accessed by multiple threads.
>
> Do we have something that makes these properties accessible to just one
> request / thread even tough they are servlet's class properties?
>
> Thanks,
> Daniel
>
> _______________________________________________
> weld-dev mailing list
> weld-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev


More information about the weld-dev mailing list