zoukankan      html  css  js  c++  java
  • struts ActionContext ThreadLocal

    public class ActionContext implements Serializable

       The ActionContext is the context in which an Action is executed. Each context is basically a container of objects an action

    needs for execution like the session, parameters, locale, etc.

       The ActionContext is thread local which means that values stored in the ActionContext are unique per thread. The benefit

    of this is you don't need to worry about a user specific action context, you just get it:

                                      ActionContext context = ActionContext.getContext();

    Finally, because of the thread local usage you don't need to worry about making your actions thread safe.

    1.源码分析

     1 public class ActionContext implements Serializable {
     2     static ThreadLocal actionContext = new ThreadLocal();
     3     
     4     Map<String, Object> context;
     5 
     6     
     7     public ActionContext(Map<String, Object> context) {
     8         this.context = context;
     9     }
    10 
    11     public static ActionContext getContext() {
    12         return (ActionContext) actionContext.get();
    13 
    14         // Don't do lazy context creation, as it requires container; the creation of which may 
    15         // precede the context creation
    16         //if (context == null) {
    17         //    ValueStack vs = ValueStackFactory.getFactory().createValueStack();
    18         //    context = new ActionContext(vs.getContext());
    19         //    setContext(context);
    20         //}
    21 
    22     }
    23 
    24 
    25     public void setContextMap(Map<String, Object> contextMap) {
    26         getContext().context = contextMap;
    27     }
    28 
    29     //.....
    30 
    31 }
  • 相关阅读:
    sql 从A表复制数据到B表
    sql union和union all
    sql 类型转换
    SQL聚合函数
    数据存储类型
    asp.net中XML如何做增删改查操作(基础操作)
    数据库分页总结
    javascript 和 jquery 初学总结
    File FileStream StreamReader和StreamWriter
    oracle建数据库
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3236458.html
Copyright © 2011-2022 走看看