public class MyAction extends Action {
  private Ojbect a=..;
  public ActionForward execute(.....){
    Ojbect b=...;
  }
}b 是线程安全的,a 如果只读,也是线程安全的。

解决方案 »

  1.   

    但是我又看到很多程序中在进行登陆验证后,也是在execute()方法中将用户值保存到session里面的,把我弄糊涂了,不知是怎么回事
      

  2.   

    是啊,session在excute方法里是线程安全的,但作为action的类变量就不行了public class MyAction extends Action {
      private HttpSession a=..; //会有同步问题  public ActionForward execute(.....){
        HttpSession b=...; //线程安全
      }
    }