java.lang.ThreadLocal.remove()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中java.lang.ThreadLocal.remove()方法的一些代码示例,展示了ThreadLocal.remove()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadLocal.remove()方法的具体详情如下:
包路径:java.lang.ThreadLocal
类名称:ThreadLocal
方法名:remove

ThreadLocal.remove介绍

[英]Removes the entry for this variable in the current thread. If this call is followed by a #get() before a #set, #get() will call #initialValue() and create a new entry with the resulting value.
[中]删除当前线程中此变量的条目。如果此调用之后是#set之前的#get(),则#get()将调用#initialValue(),并使用结果值创建一个新条目。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Reset the SimpAttributes for the current thread.
 */
public static void resetAttributes() {
  attributesHolder.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Reset the JodaTimeContext for the current thread.
 */
public static void resetJodaTimeContext() {
  jodaTimeContextHolder.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Remove any user credentials for this proxy from the current thread.
 * Statically specified user credentials apply again afterwards.
 * @see #setCredentialsForCurrentThread
 */
public void removeCredentialsFromCurrentThread() {
  this.threadBoundCredentials.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Remove any ConnectionSpec for this proxy from the current thread.
 * A statically specified ConnectionSpec applies again afterwards.
 * @see #setConnectionSpecForCurrentThread
 */
public void removeConnectionSpecFromCurrentThread() {
  this.threadBoundSpec.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Remove any user credentials for this proxy from the current thread.
 * Statically specified user credentials apply again afterwards.
 * @see #setCredentialsForCurrentThread
 */
public void removeCredentialsFromCurrentThread() {
  this.threadBoundCredentials.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Reset the RequestAttributes for the current thread.
 */
public static void resetRequestAttributes() {
  requestAttributesHolder.remove();
  inheritableRequestAttributesHolder.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Reset the DateTimeContext for the current thread.
 */
public static void resetDateTimeContext() {
  dateTimeContextHolder.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Reset the LocaleContext for the current thread.
 */
public static void resetLocaleContext() {
  localeContextHolder.remove();
  inheritableLocaleContextHolder.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Clear the entire transaction synchronization state for the current thread:
 * registered synchronizations as well as the various transaction characteristics.
 * @see #clearSynchronization()
 * @see #setCurrentTransactionName
 * @see #setCurrentTransactionReadOnly
 * @see #setCurrentTransactionIsolationLevel
 * @see #setActualTransactionActive
 */
public static void clear() {
  synchronizations.remove();
  currentTransactionName.remove();
  currentTransactionReadOnly.remove();
  currentTransactionIsolationLevel.remove();
  actualTransactionActive.remove();
}

代码示例来源:origin: shuzheng/zheng

/**
 * 清除数据源
 */
public static void clearDataSource() {
  CONTEXT_HOLDER.remove();
}

代码示例来源:origin: netty/netty

public static void destroy() {
  slowThreadLocalMap.remove();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the name of the currently proxied bean instance.
 * @param beanName the name of the bean, or {@code null} to reset it
 */
static void setCurrentProxiedBeanName(@Nullable String beanName) {
  if (beanName != null) {
    currentProxiedBeanName.set(beanName);
  }
  else {
    currentProxiedBeanName.remove();
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
static TransactionContext removeCurrentTransactionContext() {
  TransactionContext transactionContext = currentTransactionContext.get();
  currentTransactionContext.remove();
  return transactionContext;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Deactivate transaction synchronization for the current thread.
 * Called by the transaction manager on transaction cleanup.
 * @throws IllegalStateException if synchronization is not active
 */
public static void clearSynchronization() throws IllegalStateException {
  if (!isSynchronizationActive()) {
    throw new IllegalStateException("Cannot deactivate transaction synchronization - not active");
  }
  logger.trace("Clearing transaction synchronization");
  synchronizations.remove();
}

代码示例来源:origin: apache/incubator-dubbo

public static void remove() {
  Thread thread = Thread.currentThread();
  if (thread instanceof InternalThread) {
    ((InternalThread) thread).setThreadLocalMap(null);
  } else {
    slowThreadLocalMap.remove();
  }
}

代码示例来源:origin: apache/incubator-dubbo

public static void remove() {
  Thread thread = Thread.currentThread();
  if (thread instanceof InternalThread) {
    ((InternalThread) thread).setThreadLocalMap(null);
  } else {
    slowThreadLocalMap.remove();
  }
}

代码示例来源:origin: netty/netty

public static void remove() {
  Thread thread = Thread.currentThread();
  if (thread instanceof FastThreadLocalThread) {
    ((FastThreadLocalThread) thread).setThreadLocalMap(null);
  } else {
    slowThreadLocalMap.remove();
  }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Dispose of targets if necessary; clear ThreadLocal.
 * @see #destroyPrototypeInstance
 */
@Override
public void destroy() {
  logger.debug("Destroying ThreadLocalTargetSource bindings");
  synchronized (this.targetSet) {
    for (Object target : this.targetSet) {
      destroyPrototypeInstance(target);
    }
    this.targetSet.clear();
  }
  // Clear ThreadLocal, just in case.
  this.targetInThread.remove();
}

代码示例来源:origin: google/guava

public final void tearDown() throws IOException {
  if (!fileThreadLocal.get().delete()) {
   logger.warning("Unable to delete file: " + fileThreadLocal.get());
  }
  fileThreadLocal.remove();
 }
}

代码示例来源:origin: google/guava

public final void tearDown() throws IOException {
  try {
   java.nio.file.Files.delete(fileThreadLocal.get());
  } catch (IOException e) {
   logger.log(Level.WARNING, "Unable to delete file: " + fileThreadLocal.get(), e);
  }
  fileThreadLocal.remove();
 }
}

相关文章