public static ShardingVO getShardingVo(){ return contextHolder.get(); }
public static void setShardingVo(ShardingVO shardingVo){ contextHolder.set(shardingVo); }
/** * Clear all entries in the MDC. */ public void clear() { Map map = (Map) inheritableThreadLocal.get(); if (map != null) { map.clear(); // the InheritableThreadLocal.remove method was introduced in JDK 1.5 // Thus, invoking clear() on previous JDK 1.4 will fail if(isJDK14()) { inheritableThreadLocal.set(null); } else { inheritableThreadLocal.remove(); } } }
/** * Remove the current thread's value for baseUri thread-local variable (set by {@link #setBaseUri(java.net.URI)}). * * Should be called after resource method invocation for cleanup. * * @see #location(java.net.URI) * @since 2.4 */ public static void clearBaseUri() { baseUriThreadLocal.remove(); }
/** * 创建本地线程对象 * * @param <T> 持有对象类型 * @param isInheritable 是否为子线程提供从父线程那里继承的值 * @return 本地线程 */ public static <T> ThreadLocal<T> createThreadLocal(boolean isInheritable) { if (isInheritable) { return new InheritableThreadLocal<>(); } else { return new ThreadLocal<>(); } }
public static void setThreadAttemptId(String attemptId) { assert attemptId != null; threadAttemptId.set(attemptId); }
/** * Remove the current thread's value for baseUri thread-local variable (set by {@link #setBaseUri(java.net.URI)}). * * Should be called after resource method invocation for cleanup. * * @see #location(java.net.URI) * @since 2.4 */ public static void clearBaseUri() { baseUriThreadLocal.remove(); }
/** * 创建本地线程对象 * * @param <T> 持有对象类型 * @param isInheritable 是否为子线程提供从父线程那里继承的值 * @return 本地线程 */ public static <T> ThreadLocal<T> createThreadLocal(boolean isInheritable) { if (isInheritable) { return new InheritableThreadLocal<>(); } else { return new ThreadLocal<>(); } }
/** * Return request baseUri previously set by {@link #setBaseUri(java.net.URI)}. * * Returned {@link URI} is used for absolutization of the location header in case that only a relative * {@code URI} was provided. * * @return baseUri of the actual request * @see #location(java.net.URI) * @since 2.4 */ private static URI getBaseUri() { return baseUriThreadLocal.get(); }
/** * Binds the specified stream to the current thread. * * @param output * the stream to bind * @return the OutputStream that was previously active */ public OutputStream bindStream(final OutputStream output) { final OutputStream stream = outputStreamThreadLocal.get(); outputStreamThreadLocal.set(output); return stream; }
/** * Register a {@link SharedResourcesBroker} to be used as the implicit broker for this and all new children threads. */ public static void registerImplicitBroker(SharedResourcesBroker<?> broker) { threadLocalBroker.set(broker); }
/** * Remove the analysis cache for the current thread. This should be called * after all analysis is complete * */ public static void removeAnalysisCacheForCurrentThread() { analysisCacheThreadLocal.remove(); }
@Override public void execute(Runnable command) { if (command instanceof AsyncLoadFuture) { AsyncLoadFuture afuture = (AsyncLoadFuture) command; boolean flag = afuture.getConfig().getNeedThreadLocalSupport(); if (flag) { Thread thread = Thread.currentThread(); if (ReflectionUtils.getField(threadLocalField, thread) == null) { // 创建一个空的ThreadLocal,立马写回去 new ThreadLocal<Boolean>(); // 这时会在runner线程产生一空记录的ThreadLocalMap记录 } if (ReflectionUtils.getField(inheritableThreadLocalField, thread) == null) { // 创建一个空的ThreadLocal,立马写回去 new InheritableThreadLocal<Boolean>(); // 可继承的ThreadLocal } } } super.execute(command);// 调用父类进行提交 }
/** * Return request baseUri previously set by {@link #setBaseUri(java.net.URI)}. * * Returned {@link URI} is used for absolutization of the location header in case that only a relative * {@code URI} was provided. * * @return baseUri of the actual request * @see #location(java.net.URI) * @since 2.4 */ private static URI getBaseUri() { return baseUriThreadLocal.get(); }