@Test public void testThreadLocalInheritableIfConfigured() { System.setProperty(DefaultThreadContextMap.INHERITABLE_MAP, "true"); ThreadContextMapFactory.init(); try { final ThreadLocal<Map<String, String>> threadLocal = DefaultThreadContextMap.createThreadLocalMap(true); assertTrue(threadLocal instanceof InheritableThreadLocal<?>); } finally { System.clearProperty(DefaultThreadContextMap.INHERITABLE_MAP); } } }
/** * <em>Consider private, used for testing.</em> */ static void init() { ThreadContextMapFactory.init(); contextMap = null; final PropertiesUtil managerProps = PropertiesUtil.getProperties(); disableAll = managerProps.getBooleanProperty(DISABLE_ALL); useStack = !(managerProps.getBooleanProperty(DISABLE_STACK) || disableAll); useMap = !(managerProps.getBooleanProperty(DISABLE_MAP) || disableAll); contextStack = new DefaultThreadContextStack(useStack); if (!useMap) { contextMap = new NoOpThreadContextMap(); } else { contextMap = ThreadContextMapFactory.createThreadContextMap(); } if (contextMap instanceof ReadOnlyThreadContextMap) { readOnlyContextMap = (ReadOnlyThreadContextMap) contextMap; } else { readOnlyContextMap = null; } }