【问题标题】:why exist initContextServletContext in JSF Mojarra 2.2 FacesContext.java为什么在 JSF Mojarra 2.2 FacesContext.java 中存在 initContextServletContext
【发布时间】:2015-09-09 08:56:28
【问题描述】:
private static ConcurrentHashMap initContextServletContext = new ConcurrentHashMap(2);

字段是私有的,但从未在 FacesContext 类中使用。有存在的理由吗?

【问题讨论】:

    标签: jsf mojarra facescontext


    【解决方案1】:

    它在 Mojarra 特定的 com.sun.faces.config.InitFacesContext 实现中通过反射访问,仅在容器初始化期间使用(行号与 Mojarra 2.2.11 匹配):

    675    static Map getThreadInitContextMap() {
    676        ConcurrentHashMap threadInitContext = null;
    677        try {
    678            Field threadMap = FacesContext.class.getDeclaredField("threadInitContext");
    679            threadMap.setAccessible(true);
    680            threadInitContext = (ConcurrentHashMap)threadMap.get(null);
    681        } catch (Exception e) {
    682            if (LOGGER.isLoggable(Level.FINEST)) {
    683                LOGGER.log(Level.FINEST, "Unable to get (thread, init context) map", e);
    684            }
    685        }
    686        return threadInitContext;
    687    }
    

    另见:

    【讨论】:

    • 非常感谢。有什么推荐的书或文章吗?
    • 不是关于实现细节的。继续阅读源代码:)
    猜你喜欢
    • 2015-11-04
    • 2015-12-25
    • 1970-01-01
    • 2013-07-14
    • 2012-12-02
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多