/** * Whether SSL State/Context should be reset * Shared state for any HC based implementation, because SSL contexts are the same */protectedstaticfinalThreadLocal<Boolean>resetStateOnThreadGroupIteration=ThreadLocal.withInitial(() ->Boolean.FALSE);
/** * Reset SSL State. <br/> * In order to do that we need to: * <ul> * <li>Call resetContext() on SSLManager</li> * <li>Close current Idle or Expired connections that hold SSL State</li> * <li>Remove HttpClientContext.USER_TOKEN from {@link HttpClientContext}</li> * </ul> * @param jMeterVariables {@link JMeterVariables} * @param clientContext {@link HttpClientContext} * @param mapHttpClientPerHttpClientKey Map of {@link Pair} holding {@link CloseableHttpClient} and {@link private void resetStateIfNeeded(JMeterVariables jMeterVariables, HttpClientContext clientContext, Map<HttpClientKey, Pair<CloseableHttpClient, PoolingHttpClientConnectionManager>> mapHttpClientPerHttpClientKey){ if (resetStateOnThreadGroupIteration.get()) { // 关闭当前线程对应连接池的超时、空闲连接,重置连接池状态 closeCurrentConnections(mapHttpClientPerHttpClientKey); // 移除Token clientContext.removeAttribute(HttpClientContext.USER_TOKEN); // 重置SSL上下文 ((JsseSSLManager) SSLManager.getInstance()).resetContext(); // 标记置为false,保证一次循环中,只有第一个采样器走进此逻辑 resetStateOnThreadGroupIteration.set(false); } } @Override protected void notifyFirstSampleAfterLoopRestart(){ log.debug("notifyFirstSampleAfterLoopRestart called " + "with config(httpclient.reset_state_on_thread_group_iteration={})", RESET_STATE_ON_THREAD_GROUP_ITERATION); resetStateOnThreadGroupIteration.set(RESET_STATE_ON_THREAD_GROUP_ITERATION); }