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 }
  • 相关阅读:
    ubuntu video and audio
    js type
    jumpserver 堡垒机环境搭建
    ubuntu dnsmasq
    bind--dns-docker---[nslookup/dig]
    java maven scope compile,provide,system,test,runtime
    docker install and minikube install
    nginx break-circus orange api-gateway
    一个IP能建立的最大连接数是多少?
    Docker 在6.4上安装
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3236458.html
Copyright © 2011-2022 走看看