本文整理汇总了Java中io.netty.util.concurrent.FastThreadLocal类的典型用法代码示例。如果您正苦于以下问题:Java FastThreadLocal类的具体用法?Java FastThreadLocal怎么用?Java FastThreadLocal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FastThreadLocal类属于io.netty.util.concurrent包,在下文中一共展示了FastThreadLocal类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: threadLocalDeallocator
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
/**
* Ensures that {@link FastThreadLocal#remove() FastThreadLocal.remove()} is called when the {@link Runnable#run()}
* method of the given {@link Runnable} instance completes to ensure cleanup of {@link FastThreadLocal} instances.
* This is especially important for direct byte buffers allocated locally for a thread.
*/
public static Runnable threadLocalDeallocator(Runnable r)
{
return () ->
{
try
{
r.run();
}
finally
{
FastThreadLocal.removeAll();
}
};
}
示例2: DeflateCompressor
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
private DeflateCompressor()
{
deflater = new FastThreadLocal<Deflater>()
{
@Override
protected Deflater initialValue()
{
return new Deflater();
}
};
inflater = new FastThreadLocal<Inflater>()
{
@Override
protected Inflater initialValue()
{
return new Inflater();
}
};
}
示例3: destroy
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
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();
}
}
示例4: run
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
@Override
public void run() {
try {
r.run();
} finally {
FastThreadLocal.removeAll();
}
}
示例5: stop
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
@Override
public void stop() throws Exception {
future.channel().closeFuture();
// clean up internal Netty threads
FastThreadLocal.removeAll();
FastThreadLocal.destroy();
}
示例6: withInitial
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
public static <S> FastThreadLocal<S> withInitial(Supplier<? extends S> supplier) {
checkNotNull(supplier, "supplier");
return new FastThreadLocal<S>() {
@Override
protected S initialValue() throws Exception {
return supplier.get();
}
};
}
示例7: create
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
private static <T> FastThreadLocal<SoftReference<T>> create(Supplier<? extends T> supplier) {
requireNonNull(supplier);
return FastThreadLocals.withInitial(() -> {
final T value = supplier.get();
return value == null ? null : new SoftReference<>(value);
});
}
示例8: fastThreadLocal
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
@Benchmark
public int fastThreadLocal() {
int result = 0;
for (FastThreadLocal<Integer> i: fastThreadLocals) {
result += i.get();
}
return result;
}
示例9: AWSSignatureCalculatorFactory
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
public AWSSignatureCalculatorFactory(AWSCredentialsProvider credentialsProvider) {
signatureCalculator = new FastThreadLocal<AWSSignatureCalculator>() {
@Override
protected AWSSignatureCalculator initialValue() {
return new AWSSignatureCalculator(credentialsProvider);
}
};
}
示例10: FastSoftThreadLocal
import io.netty.util.concurrent.FastThreadLocal; //导入依赖的package包/类
private FastSoftThreadLocal(FastThreadLocal<SoftReference<T>> threadLocal) {
this.threadLocal = threadLocal;
}