简体   繁体   English

@SessionScoped bean是否存在并发问题?

[英]Do @SessionScoped beans have concurrency issues?

Obviously, it's easy to have multiple parallel requests accessing the same @SessionScoped bean in a web app context. 显然,在Web应用程序上下文中访问同一个@SessionScoped bean很容易有多个并行请求。 Am I correct in believing that I have to explicitly control synchronization when accessing the @SessionScoped bean within those requests? 我是否相信在访问这些请求中的@SessionScoped bean时必须显式控制同步?

Depends on what you mean by: 取决于你的意思:

explicitly control synchronization when access the @SessionScoped bean within those requests 在这些请求中访问@SessionScoped bean时显式控制同步

You are right that there may be several threads accessing the @SessionScoped bean in parallel. 你是对的,可能有几个线程并行访问@SessionScoped bean。 So generally you have to take care of the thread safety. 所以一般来说你必须要注意线程的安全性。 Whether you need to explicitly control synchronization (or synchronize at all) depends on how the shared state is used or modified from different threads. 是否需要显式控制同步(或根本不同步)取决于如何从不同线程使用或修改共享状态。 If you use classes from java.util.concurrent or java.util.concurrent.atomic , you may achieve perfect thread-safety without a single synchronized statement. 如果使用java.util.concurrentjava.util.concurrent.atomic类,则可以在没有单个synchronized语句的情况下实现完美的线程安全性。

But yes, you have to take care of thread safety. 但是,是的,你必须照顾线程安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM