For example, is there a bean that has @SessionScoped stored in an HTTPSession object behind the scene? Are there beans with @ApplicationScoped stored in the map instance variable in ServletContext?
For a web layer, this is true. If the bean instance was created, you can find it there by manually sorting through all the objects on the specified maps.
@RequestScoped is a special thing. In a web layer, this corresponds to a request attribute map, but this area also applies to calls, for example. remote beans session or message-driven beans message processing. In this case, there is no HTTP request and, therefore, there is no request attribute map. They are probably stored “somewhere else”, possibly in TLS (Thread Local Storage), which are installed and disabled by the bean proxy.
If so, what about thread safety.
Bean applications and sessions themselves are simply not thread safe. You must take care of thread safety, for example, using thread-safe data structures, a synchronized keyword, or a bean type that is essentially thread-safe (e.g. @Stateful annotated bean).
Arjan tijms
source share