看看另一个问题的答案的不相关部分,虽然我理解为什么在问题的示例中对请求和响应的引用是线程不安全的,为什么 SessionScoped bean 引用它所绑定的 HttpSession 是线程不安全的?
@SessionScoped
public class SessionManager {
HttpSession session = null;
...
@PostConstruct void initialize() {
this.session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
}
private void onLogin(@Observes @LoggedIn User user) {
// (1) housekeeping stuff
// (2) destroy older, duplicate login session, if user did not previously
// logout, in which case it would be really handy to have a reference
// to HttpSession.
}
}