b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

filterconfig struts2执行流程(5)

电脑杂谈  发布时间:2018-02-15 05:13:20  来源:网络整理

/**
 * Cleans up a request of thread locals
 */
public void cleanupRequest(HttpServletRequest request) {
    // 获取request域中计数器
    Integer counterVal = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
    if (counterVal != null) {
        // 这个计数器的值不为空就把它减一
        counterVal -= 1;
        // 重新放入request域,用CLEARUP_RECURSION_COUNTER这个常量保存
        request.setAttribute(CLEANUP_RECURSION_COUNTER, counterVal);
        // 关键:如果这个计数器在减一之后的值仍然大于0,那么就不释放它所占用的内存,记录一条日志就直接返回了
        if (counterVal > 0 ) {
            if (log.isDebugEnabled()) {
                log.debug("skipping cleanup counter="+counterVal);
            }
            return;
        }
    }
    // 否则就clearUp掉
    // always clean up the thread request, even if an action hasn't been executed
    try {
        dispatcher.cleanUpRequest(request);
    } finally {
        ActionContext.setContext(null);
        Dispatcher.setInstance(null);
    }
}

相信看到这里,大家大致已经明白了这个计数器存在的意义:记录Action被请求的次数,如果请求的次数非常频繁,说明这个Action被调用的次数非常多,那么就暂时不释放掉它所占用的内存,反之,如果只请求了一次或者是几次,那么在这个Action执行完毕后就会释放掉它所占用的内存。

跟进源码看一下具体的实现:

public class ActionContext implements Serializable {

    static ThreadLocal<ActionContext> actionContext = new ThreadLocal<ActionContext>();

    // 处理请求的Action的name
    public static final String ACTION_NAME = "com.opensymphony.xwork2.ActionContext.name";

    // 与这个Action相关的值栈
    public static final String VALUE_STACK = ValueStack.VALUE_STACK;

    // session相关
    public static final String SESSION = "com.opensymphony.xwork2.ActionContext.session";

    // application域
    public static final String APPLICATION = "com.opensymphony.xwork2.ActionContext.application";
    ...


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-78438-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 安吉丽娜
      安吉丽娜

      美国佬喜欢欺负小字辈

    热点图片
    拼命载入中...