• 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 }
  • 相关阅读:
    dayfunctools.weps 定义函数装饰器
    python3之concurrent.futures一个多线程多进程的直接对接模块,python3.2有线程池了
    python的类的super()
    django的admin
    python的单例模式
    git指南
    django创建验证码
    Django model对象接口
    Go语言基础
    迭代器&迭代对象&生成器
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3236458.html
Copyright © 2020-2023  润新知