【发布时间】:2011-04-25 06:08:07
【问题描述】:
好的,有了this question 的所有答案,我仍然无法处理我的问题。 我有以下星座:
在 JSF (1.1) webapp 中,我有一个请求范围的 bean beanof class Bean。当用户快速单击commandButton 多次以将他重定向到insult.xhtml 页面时,doSomethingThatTakesALittleLongerAndShouldOnlyBeDoneOnce 方法可能会被多次调用(在 Tomcat 6 上)。我怎样才能防止这种情况发生?
...
public Bean() {
HttpSession session = ((HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(false));
if(session != null && session.getAttribute("done") != null) {
doSomethingThatTakesALittleLongerAndShouldOnlyBeDoneOnce();
session.setAttribute("done", "done");
}
}
public void doSomethingThatTakesALittleLongerAndShouldOnlyBeDoneOnce() {
this.bossInsult = generateBossInsult();
}
侮辱.xhtml:
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
<html>
<body>
#{bean.bossInsult}
</body>
</html>
</ui:composition>
【问题讨论】:
标签: jsf httpsession thread-safety