struts1.3.8线程安全问题
@Controller("/A/aaaddd")
public class HeHAction extends org.apache.struts.actions.DispatchAction{
@Resource(name="xxxServiceBean")
private xxxService xxxService;
public ActionForward dBianList(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
各种代码.....
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,
IOException
{
i++;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" i="+i);
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
当访问这个servlet的时候,你访问多少次,I的值就是多少。
所以:我们在用struts1的时候不能在action里面定义属性。要用到只的话只能在方法里面定义。
那至于为什么把属性的定义放到方法里面就不会有多线程的问题了,这个问题希望各位读者去查看有关JMM(java memory model)里面有关java内存模式如何给方法分配内存的内容, 我相信你们会找到答案。