Java Code Examples for io.netty.util.internal.InternalThreadLocalMap#UNSET
The following examples show how to use
io.netty.util.internal.InternalThreadLocalMap#UNSET .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadLocalBenchmark.java From turbo-rpc with Apache License 2.0 | 6 votes |
@Benchmark @BenchmarkMode({ Mode.Throughput }) @OutputTimeUnit(TimeUnit.MICROSECONDS) @SuppressWarnings("unchecked") public Integer fastThreadWithArrayMap() { Object obj = fastThread.threadLocalMap().indexedVariable(1024); ConcurrentIntToObjectArrayMap<Integer> map; if (obj != InternalThreadLocalMap.UNSET) { map = (ConcurrentIntToObjectArrayMap<Integer>) obj; return map.getOrUpdate(1024, () -> value); } map = new ConcurrentIntToObjectArrayMap<>(); fastThread.threadLocalMap().setIndexedVariable(1024, map); return map.getOrUpdate(1024, () -> value); }
Example 2
Source File: FastThreadLocal.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
/** * Sets the value to uninitialized for the specified thread local map; * a proceeding call to get() will trigger a call to initialValue(). * The specified thread local map must be for the current thread. */ @SuppressWarnings("unchecked") public final void remove(InternalThreadLocalMap threadLocalMap) { if (threadLocalMap == null) { return; } Object v = threadLocalMap.removeIndexedVariable(index); removeFromVariablesToRemove(threadLocalMap, this); if (v != InternalThreadLocalMap.UNSET) { try { onRemoval((V) v); } catch (Exception e) { PlatformDependent.throwException(e); } } }
Example 3
Source File: FastThreadLocal.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
/** * Removes all {@link FastThreadLocal} variables bound to the current thread. This operation is useful when you * are in a container environment, and you don't want to leave the thread local variables in the threads you do not * manage. */ public static void removeAll() { InternalThreadLocalMap threadLocalMap = InternalThreadLocalMap.getIfSet(); if (threadLocalMap == null) { return; } try { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); if (v != null && v != InternalThreadLocalMap.UNSET) { @SuppressWarnings("unchecked") Set<FastThreadLocal<?>> variablesToRemove = (Set<FastThreadLocal<?>>) v; FastThreadLocal<?>[] variablesToRemoveArray = variablesToRemove.toArray(new FastThreadLocal[variablesToRemove.size()]); for (FastThreadLocal<?> tlv: variablesToRemoveArray) { tlv.remove(threadLocalMap); } } } finally { InternalThreadLocalMap.remove(); } }
Example 4
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
/** * Removes all {@link FastThreadLocal} variables bound to the current thread. This operation is useful when you * are in a container environment, and you don't want to leave the thread local variables in the threads you do not * manage.删除所有绑定到当前线程的FastThreadLocal变量。当您在容器环境中,并且您不想将线程局部变量留在您没有管理的线程中时,此操作非常有用。 */ // public static void removeAll() { InternalThreadLocalMap threadLocalMap = InternalThreadLocalMap.getIfSet(); if (threadLocalMap == null) { return; } try { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); if (v != null && v != InternalThreadLocalMap.UNSET) { @SuppressWarnings("unchecked") Set<FastThreadLocal<?>> variablesToRemove = (Set<FastThreadLocal<?>>) v; FastThreadLocal<?>[] variablesToRemoveArray = variablesToRemove.toArray(new FastThreadLocal[variablesToRemove.size()]); for (FastThreadLocal<?> tlv: variablesToRemoveArray) { tlv.remove(threadLocalMap); } } } finally { InternalThreadLocalMap.remove(); } }
Example 5
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
/** * Sets the value to uninitialized for the specified thread local map; * a proceeding call to get() will trigger a call to initialValue(). * The specified thread local map must be for the current thread. * 将指定的线程本地映射的值设置为未初始化;get()的进程调用将触发对initialValue()的调用。指定的线程本地映射必须针对当前线程。 */ // @SuppressWarnings("unchecked") public final void remove(InternalThreadLocalMap threadLocalMap) { if (threadLocalMap == null) { return; } Object v = threadLocalMap.removeIndexedVariable(index); removeFromVariablesToRemove(threadLocalMap, this); if (v != InternalThreadLocalMap.UNSET) { try { onRemoval((V) v); } catch (Exception e) { PlatformDependent.throwException(e); } } }
Example 6
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Returns the current value for the specified thread local map. * The specified thread local map must be for the current thread. */ @SuppressWarnings("unchecked") public final V get(InternalThreadLocalMap threadLocalMap) { Object v = threadLocalMap.indexedVariable(index); if (v != InternalThreadLocalMap.UNSET) { return (V) v; } return initialize(threadLocalMap); }
Example 7
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Set the value for the current thread. */ // public final void set(V value) { if (value != InternalThreadLocalMap.UNSET) { InternalThreadLocalMap threadLocalMap = InternalThreadLocalMap.get(); if (setKnownNotUnset(threadLocalMap, value)) { registerCleaner(threadLocalMap); } } else { remove(); } }
Example 8
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Set the value for the specified thread local map. The specified thread local map must be for the current thread.设置指定线程局部映射的值。指定的线程本地映射必须为当前线程。 */ // public final void set(InternalThreadLocalMap threadLocalMap, V value) { if (value != InternalThreadLocalMap.UNSET) { setKnownNotUnset(threadLocalMap, value); } else { remove(threadLocalMap); } }
Example 9
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private void registerCleaner(final InternalThreadLocalMap threadLocalMap) { Thread current = Thread.currentThread(); if (FastThreadLocalThread.willCleanupFastThreadLocals(current) || threadLocalMap.indexedVariable(cleanerFlagIndex) != InternalThreadLocalMap.UNSET) { return; } // removeIndexedVariable(cleanerFlagIndex) isn't necessary because the finally cleanup is tied to the lifetime // of the thread, and this Object will be discarded if the associated thread is GCed. // removeIndexedVariable(cleanerFlagIndex)不是必需的,因为最终的清理与生命周期有关 //线程,如果关联的线程是GCed,这个对象将被丢弃。 threadLocalMap.setIndexedVariable(cleanerFlagIndex, Boolean.TRUE); // We will need to ensure we will trigger remove(InternalThreadLocalMap) so everything will be released // and FastThreadLocal.onRemoval(...) will be called. //我们需要确保我们将触发remove(InternalThreadLocalMap),以便释放所有内容 //和fastthreadlocal.onremove(…)将被调用。 ObjectCleaner.register(current, new Runnable() { @Override public void run() { remove(threadLocalMap); // It's fine to not call InternalThreadLocalMap.remove() here as this will only be triggered once // the Thread is collected by GC. In this case the ThreadLocal will be gone away already.在这里不调用InternalThreadLocalMap.remove()是可以的,因为它只会被触发一次 //线程被GC收集。在这种情况下,ThreadLocal已经消失了。 } }); }
Example 10
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Returns the current value for the current thread 返回当前线程的当前值 */ @SuppressWarnings("unchecked") public final V get() { InternalThreadLocalMap threadLocalMap = InternalThreadLocalMap.get(); Object v = threadLocalMap.indexedVariable(index); if (v != InternalThreadLocalMap.UNSET) { return (V) v; } V value = initialize(threadLocalMap); registerCleaner(threadLocalMap); return value; }
Example 11
Source File: ThreadLocalBenchmark.java From turbo-rpc with Apache License 2.0 | 5 votes |
@Benchmark @BenchmarkMode({ Mode.Throughput }) @OutputTimeUnit(TimeUnit.MICROSECONDS) public Integer fastThread() { Object obj = fastThread.threadLocalMap().indexedVariable(256); if (obj != InternalThreadLocalMap.UNSET) { return (Integer) obj; } Integer value = 100; fastThread.threadLocalMap().setIndexedVariable(256, value); return value; }
Example 12
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private static void removeFromVariablesToRemove( InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); if (v == InternalThreadLocalMap.UNSET || v == null) { return; } @SuppressWarnings("unchecked") Set<FastThreadLocal<?>> variablesToRemove = (Set<FastThreadLocal<?>>) v; variablesToRemove.remove(variable); }
Example 13
Source File: FastThreadLocal.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); Set<FastThreadLocal<?>> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<FastThreadLocal<?>, Boolean>()); threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); } else { variablesToRemove = (Set<FastThreadLocal<?>>) v; } variablesToRemove.add(variable); }
Example 14
Source File: FastThreadLocal.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
private static void removeFromVariablesToRemove( InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); if (v == InternalThreadLocalMap.UNSET || v == null) { return; } @SuppressWarnings("unchecked") Set<FastThreadLocal<?>> variablesToRemove = (Set<FastThreadLocal<?>>) v; variablesToRemove.remove(variable); }
Example 15
Source File: FastThreadLocal.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * Returns the current value for the specified thread local map. * The specified thread local map must be for the current thread. */ @SuppressWarnings("unchecked") public final V get(InternalThreadLocalMap threadLocalMap) { Object v = threadLocalMap.indexedVariable(index); if (v != InternalThreadLocalMap.UNSET) { return (V) v; } return initialize(threadLocalMap); }
Example 16
Source File: FastThreadLocal.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * Set the value for the current thread. */ public final void set(V value) { if (value != InternalThreadLocalMap.UNSET) { set(InternalThreadLocalMap.get(), value); } else { remove(); } }
Example 17
Source File: FastThreadLocal.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * Set the value for the specified thread local map. The specified thread local map must be for the current thread. */ public final void set(InternalThreadLocalMap threadLocalMap, V value) { if (value != InternalThreadLocalMap.UNSET) { if (threadLocalMap.setIndexedVariable(index, value)) { addToVariablesToRemove(threadLocalMap, this); } } else { remove(threadLocalMap); } }
Example 18
Source File: FastThreadLocal.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); Set<FastThreadLocal<?>> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<FastThreadLocal<?>, Boolean>()); threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); } else { variablesToRemove = (Set<FastThreadLocal<?>>) v; } variablesToRemove.add(variable); }