类io.netty.util.concurrent.FastThreadLocal源码实例Demo

下面列出了怎么用io.netty.util.concurrent.FastThreadLocal的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: blog   文件: FastThreadLocalTest3.java
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();
}
 
源代码2 项目: blog   文件: FastThreadLocalTest3.java
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);
}
 
public FstSerializationRedisSerializer(Supplier<FSTConfiguration> supplier) {

        this(new FastThreadLocal<FSTConfiguration>() {
            @Override
            protected FSTConfiguration initialValue() {
                return supplier.get();
            }
        });
    }
 
@Benchmark
public int fastThreadLocal() {
    int result = 0;
    for (FastThreadLocal<Integer> i: fastThreadLocals) {
        result += i.get();
    }
    return result;
}
 
@Benchmark
public int fastThreadLocal() {
    int result = 0;
    for (FastThreadLocal<Integer> i: fastThreadLocals) {
        result += i.get();
    }
    return result;
}
 
源代码6 项目: netty-4.1.22   文件: PooledByteBufAllocatorTest.java
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();
        }
    };
}
 
源代码7 项目: firebase-admin-java   文件: RepoManager.java
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();
  }
}
 
源代码8 项目: saluki   文件: NamedThreadFactory.java
@Override
public void run() {
    try {
        r.run();
    } finally {
        FastThreadLocal.removeAll();
    }
}
 
源代码9 项目: Jupiter   文件: AffinityNettyThreadFactory.java
@Override
public void run() {
    try {
        r.run();
    } finally {
        FastThreadLocal.removeAll();
    }
}
 
@Benchmark
public int fastThreadLocal() {
    int result = 0;
    for (FastThreadLocal<Integer> i: fastThreadLocals) {
        result += i.get();
    }
    return result;
}
 
 类所在包
 类方法
 同包方法