public class SmsClientAction extends DispatchAction {
int temp;
public ActionForward getA(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
temp = 1;
System.out.println("A"+temp);
}
public ActionForward getB(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
temp = 2;
System.out.println("B"+temp);
}
}
}
如上所示。我做个线程里面循环 同时请求getA 和getB 会不会产生temp值乱了的问题? 如果int temp定义为private 呢?
这样一定会出问题的,
temp你没有加同步,
int temp定义为private 也没用
你要加上同步代码或这么定义
volatile int temp;
这个和struts无关吧,还有你上面的两个方法应该有返回值吧,你每次都给temp重新赋值,我感觉和在方法里面定义的一样,不过名字相同而已
[code]不明白,等看正确答案,up[/code]
就代码看没有问题
[quote]我做个线程里面循环 同时请求getA 和getB 会不会产生temp值乱了的问题? 如果int temp定义为private 呢? [/quote]
一个action同时接受多个并发请求,会造成temp混乱,不管是否private