本文整理了Java中java.lang.ThreadLocal.<init>()
方法的一些代码示例,展示了ThreadLocal.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadLocal.<init>()
方法的具体详情如下:
包路径:java.lang.ThreadLocal
类名称:ThreadLocal
方法名:<init>
[英]Creates a new thread-local variable.
[中]
代码示例来源:origin: h2oai/h2o-3
public ThreadLocal<BackendModel> getModel() {
if(null == _model) {
_model = new ThreadLocal<>();
}
return _model;
}
代码示例来源:origin: stackoverflow.com
class StaticClass {
static private ThreadLocal threadLocal = new ThreadLocal<User>();
static ThreadLocal<User> getThreadLocal() {
return threadLocal;
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
private ThreadLocal<StringMap> createThreadLocalMap() {
if (inheritableMap) {
return new InheritableThreadLocal<StringMap>() {
@Override
protected StringMap childValue(final StringMap parentValue) {
return parentValue != null ? createStringMap(parentValue) : null;
}
};
}
// if not inheritable, return plain ThreadLocal with null as initial value
return new ThreadLocal<>();
}
代码示例来源:origin: apache/hive
public ThriftCLIService(CLIService service, String serviceName) {
super(serviceName);
this.cliService = service;
currentServerContext = new ThreadLocal<ServerContext>();
}
代码示例来源:origin: apache/ignite
/**
* @param async Async enabled flag.
*/
public AsyncSupportAdapter(boolean async) {
if (async)
curFut = new ThreadLocal<>();
}
代码示例来源:origin: wildfly/wildfly
/**
* Construct a new instance.
*/
protected PeerIdentityContext() {
currentIdentity = new ThreadLocal<>();
}
代码示例来源:origin: com.google.inject/guice
InjectorImpl(InjectorImpl parent, State state, InjectorOptions injectorOptions) {
this.parent = parent;
this.state = state;
this.options = injectorOptions;
if (parent != null) {
localContext = parent.localContext;
} else {
// No ThreadLocal.initialValue(), as that would cause classloader leaks. See
// https://github.com/google/guice/issues/288#issuecomment-48216933,
// https://github.com/google/guice/issues/288#issuecomment-48216944
localContext = new ThreadLocal<>();
}
}
代码示例来源:origin: requery/requery
ThreadLocalTransaction(RuntimeConfiguration configuration) {
this.threadLocal = new ThreadLocal<>();
this.configuration = configuration;
}
代码示例来源:origin: alibaba/fastjson
public abstract class BeforeFilter implements SerializeFilter {
private static final ThreadLocal<JSONSerializer> serializerLocal = new ThreadLocal<JSONSerializer>();
private static final ThreadLocal<Character> seperatorLocal = new ThreadLocal<Character>();
private final static Character COMMA = Character.valueOf(',');
final char writeBefore(JSONSerializer serializer, Object object, char seperator) {
serializerLocal.set(serializer);
seperatorLocal.set(seperator);
writeBefore(object);
serializerLocal.set(null);
return seperatorLocal.get();
}
protected final void writeKeyValue(String key, Object value) {
JSONSerializer serializer = serializerLocal.get();
char seperator = seperatorLocal.get();
serializer.writeKeyValue(seperator, key, value);
if (seperator != ',') {
seperatorLocal.set(COMMA);
}
}
public abstract void writeBefore(Object object);
}
代码示例来源:origin: alibaba/fastjson
/**
* @since 1.1.35
*/
public abstract class AfterFilter implements SerializeFilter {
private static final ThreadLocal<JSONSerializer> serializerLocal = new ThreadLocal<JSONSerializer>();
private static final ThreadLocal<Character> seperatorLocal = new ThreadLocal<Character>();
private final static Character COMMA = Character.valueOf(',');
final char writeAfter(JSONSerializer serializer, Object object, char seperator) {
serializerLocal.set(serializer);
seperatorLocal.set(seperator);
writeAfter(object);
serializerLocal.set(null);
return seperatorLocal.get();
}
protected final void writeKeyValue(String key, Object value) {
JSONSerializer serializer = serializerLocal.get();
char seperator = seperatorLocal.get();
serializer.writeKeyValue(seperator, key, value);
if (seperator != ',') {
seperatorLocal.set(COMMA);
}
}
public abstract void writeAfter(Object object);
}
代码示例来源:origin: apache/hive
public JobContextImpl(JavaSparkContext sc, File localTmpDir) {
this.sc = sc;
this.monitorCb = new ThreadLocal<MonitorCallback>();
monitoredJobs = new ConcurrentHashMap<String, List<JavaFutureAction<?>>>();
addedJars = new ConcurrentHashMap<>();
this.localTmpDir = localTmpDir;
}
代码示例来源:origin: robolectric/robolectric
@Resetter
public static void reset() {
// sAnimationHelper is a static field used for processing delayed animations. Since it registers
// callbacks on the Choreographer, this is a problem if not reset between tests (as once the
// test is complete, its scheduled callbacks would be removed, but the static object would still
// believe it was registered and not re-register for the next test).
ReflectionHelpers.setStaticField(
RenderNodeAnimator.class, "sAnimationHelper", new ThreadLocal<>());
}
代码示例来源:origin: robolectric/robolectric
@Resetter
public static void reset() {
_ViewRootImpl_ _viewRootImplStatic_ = reflector(_ViewRootImpl_.class);
_viewRootImplStatic_.setRunQueues(new ThreadLocal<>());
_viewRootImplStatic_.setFirstDrawHandlers(new ArrayList<>());
_viewRootImplStatic_.setFirstDrawComplete(false);
_viewRootImplStatic_.setConfigCallbacks(new ArrayList<>());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testTimeoutStreamEndCallbackAsynchronously() {
TimeoutStream stream = vertx.timerStream(200);
ThreadLocal<Object> stack = new ThreadLocal<>();
stack.set(true);
stream.endHandler(v2 -> {
assertTrue(Vertx.currentContext().isEventLoopContext());
assertNull(stack.get());
testComplete();
});
stream.handler(id -> {
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testConsumerHandlesCompletionAsynchronously2() {
MessageConsumer<Object> consumer = eb.consumer(ADDRESS1);
consumer.handler(msg -> {
});
ThreadLocal<Object> stack = new ThreadLocal<>();
stack.set(true);
consumer.completionHandler(v -> {
assertNull(stack.get());
assertTrue(Vertx.currentContext().isEventLoopContext());
testComplete();
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testConsumerHandlesCompletionAsynchronously() {
MessageConsumer<Object> consumer = eb.consumer(ADDRESS1);
ThreadLocal<Object> stack = new ThreadLocal<>();
stack.set(true);
consumer.completionHandler(v -> {
assertNull(stack.get());
assertTrue(Vertx.currentContext().isEventLoopContext());
testComplete();
});
consumer.handler(msg -> {
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testEndHandler() {
ThreadLocal<Object> stack = new ThreadLocal<>();
stack.set(true);
peer2 = vertx.createDatagramSocket(new DatagramSocketOptions());
peer2.listen(1234, "127.0.0.1", ar -> {
assertTrue(ar.succeeded());
peer2.endHandler(v -> {
assertTrue(Vertx.currentContext().isEventLoopContext());
assertNull(stack.get());
testComplete();
});
peer2.close();
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testAsyncFileCloseHandlerIsAsync() throws Exception {
String fileName = "some-file.dat";
createFileWithJunk(fileName, 100);
AsyncFile file = vertx.fileSystem().openBlocking(testDir + pathSep + fileName, new OpenOptions());
ThreadLocal stack = new ThreadLocal();
stack.set(true);
file.close(ar -> {
assertNull(stack.get());
assertTrue(Vertx.currentContext().isEventLoopContext());
testComplete();
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testConsumerHandlesCompletionAsynchronously1() {
startNodes(2);
MessageConsumer<Object> consumer = vertices[0].eventBus().consumer(ADDRESS1);
ThreadLocal<Object> stack = new ThreadLocal<>();
stack.set(true);
consumer.completionHandler(v -> {
assertTrue(Vertx.currentContext().isEventLoopContext());
assertNull(stack.get());
testComplete();
});
consumer.handler(msg -> {});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testConsumerHandlesCompletionAsynchronously2() {
startNodes(2);
MessageConsumer<Object> consumer = vertices[0].eventBus().consumer(ADDRESS1);
consumer.handler(msg -> {
});
ThreadLocal<Object> stack = new ThreadLocal<>();
stack.set(true);
consumer.completionHandler(v -> {
assertTrue(Vertx.currentContext().isEventLoopContext());
assertNull(stack.get());
testComplete();
});
await();
}
内容来源于网络,如有侵权,请联系作者删除!