简体   繁体   中英

Spring session scope bean, thread-safety

I am building an application with Struts2, Spring, Hibernate. Struts actions are managed by Spring, their scopes are "request" and I have session bean with some state for performing a conversation. Before I used Struts2 session map, but I wanted the "containsKey, put, get, cast" nightmare to dissapear. So I started using session scope bean managed by Spring.

Question: this bean isn't thread-safe? If we have multiple-windows-per-user-per-browser, we can get many threads in session bean? How to handle it? Build thread-safe session bean?

Yes. Everything stored in a scope larger than request is potentially accessed by multiple threads, and must be thread-safe.

If you are concerned about "multiple-windows-per-user-per-browser" and also avoiding the "containsKey, put, get, cast" nightmare in Struts2, you could also look at the struts2-conversation plugin . The plugin would manage the thread-safety issues for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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