io.netty.util.concurrent.FastThreadLocal Java Examples
The following examples show how to use
io.netty.util.concurrent.FastThreadLocal.
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: FastThreadLocalTest3.java From blog with BSD 2-Clause "Simplified" License | 6 votes |
public static void test1() { int size = 10000; FastThreadLocal<String> tls[] = new FastThreadLocal[size]; for (int i = 0; i < size; i++) { tls[i] = new FastThreadLocal<String>(); } new FastThreadLocalThread(new Runnable() { @Override public void run() { long starTime = System.currentTimeMillis(); for (int i = 0; i < size; i++) { tls[i].set("value" + i); } for (int i = 0; i < size; i++) { for (int k = 0; k < 100000; k++) { tls[i].get(); } } System.out.println(System.currentTimeMillis() - starTime + "ms"); } }).start(); }
Example #2
Source File: FastThreadLocalTest3.java From blog with BSD 2-Clause "Simplified" License | 6 votes |
public static void test2() throws Exception { CountDownLatch cdl = new CountDownLatch(10000); FastThreadLocal<String> threadLocal = new FastThreadLocal<String>(); long starTime = System.currentTimeMillis(); for (int i = 0; i < 10000; i++) { new FastThreadLocalThread(new Runnable() { @Override public void run() { threadLocal.set(Thread.currentThread().getName()); for (int k = 0; k < 100000; k++) { threadLocal.get(); } cdl.countDown(); } }, "Thread" + (i + 1)).start(); } cdl.await(); System.out.println(System.currentTimeMillis() - starTime); }
Example #3
Source File: FstSerializationRedisSerializer.java From jetlinks-community with Apache License 2.0 | 5 votes |
public FstSerializationRedisSerializer(Supplier<FSTConfiguration> supplier) { this(new FastThreadLocal<FSTConfiguration>() { @Override protected FSTConfiguration initialValue() { return supplier.get(); } }); }
Example #4
Source File: FastThreadLocalFastPathBenchmark.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Benchmark public int fastThreadLocal() { int result = 0; for (FastThreadLocal<Integer> i: fastThreadLocals) { result += i.get(); } return result; }
Example #5
Source File: FastThreadLocalSlowPathBenchmark.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Benchmark public int fastThreadLocal() { int result = 0; for (FastThreadLocal<Integer> i: fastThreadLocals) { result += i.get(); } return result; }
Example #6
Source File: PooledByteBufAllocatorTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private static ThreadCache createNewThreadCache(final PooledByteBufAllocator allocator) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch cacheLatch = new CountDownLatch(1); final Thread t = new FastThreadLocalThread(new Runnable() { @Override public void run() { ByteBuf buf = allocator.newHeapBuffer(1024, 1024); // Countdown the latch after we allocated a buffer. At this point the cache must exists. cacheLatch.countDown(); buf.writeZero(buf.capacity()); try { latch.await(); } catch (InterruptedException e) { throw new IllegalStateException(e); } buf.release(); FastThreadLocal.removeAll(); } }); t.start(); // Wait until we allocated a buffer and so be sure the thread was started and the cache exists. cacheLatch.await(); return new ThreadCache() { @Override public void destroy() throws InterruptedException { latch.countDown(); t.join(); } }; }
Example #7
Source File: RepoManager.java From firebase-admin-java with Apache License 2.0 | 5 votes |
public static void destroy(Context ctx) { try { instance.destroyInternal(ctx); } finally { ctx.stop(); // Clean up Netty thread locals, which will also clean up any dangling threadDeathWatcher // daemons. See https://github.com/netty/netty/issues/7310 for more context. FastThreadLocal.removeAll(); } }
Example #8
Source File: NamedThreadFactory.java From saluki with Apache License 2.0 | 5 votes |
@Override public void run() { try { r.run(); } finally { FastThreadLocal.removeAll(); } }
Example #9
Source File: AffinityNettyThreadFactory.java From Jupiter with Apache License 2.0 | 5 votes |
@Override public void run() { try { r.run(); } finally { FastThreadLocal.removeAll(); } }
Example #10
Source File: FastThreadLocalBenchmark.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Benchmark public int fastThreadLocal() { int result = 0; for (FastThreadLocal<Integer> i: fastThreadLocals) { result += i.get(); } return result; }