本文整理了Java中java.lang.Thread.currentThread()
方法的一些代码示例,展示了Thread.currentThread()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.currentThread()
方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:currentThread
[英]Returns a reference to the currently executing thread object.
[中]
代码示例来源:origin: iluwatar/java-design-patterns
@Override
public void run() {
readLock.lock();
try {
read();
} catch (InterruptedException e) {
LOGGER.info("InterruptedException when reading", e);
Thread.currentThread().interrupt();
} finally {
readLock.unlock();
}
}
代码示例来源:origin: iluwatar/java-design-patterns
@Override
public void run() {
writeLock.lock();
try {
write();
} catch (InterruptedException e) {
LOGGER.info("InterruptedException when writing", e);
Thread.currentThread().interrupt();
} finally {
writeLock.unlock();
}
}
代码示例来源:origin: iluwatar/java-design-patterns
@Override
public void run() {
LOGGER.info("{} processing {}", Thread.currentThread().getName(), task.toString());
try {
Thread.sleep(task.getTimeMs());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: ReactiveX/RxJava
static void uncaught(@NonNull Throwable error) {
Thread currentThread = Thread.currentThread();
UncaughtExceptionHandler handler = currentThread.getUncaughtExceptionHandler();
handler.uncaughtException(currentThread, error);
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public String apply(String v) {
System.out.println("ObserveOn Thread: " + Thread.currentThread());
return v;
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public void run() {
t = Thread.currentThread();
latch.countDown();
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void accept(Throwable throwable) throws Exception {
thread.set(Thread.currentThread());
latch.countDown();
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public void run() throws Exception {
name[0] = Thread.currentThread().getName();
cdl.countDown();
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public void accept(Throwable throwable) throws Exception {
thread.set(Thread.currentThread());
latch.countDown();
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
}),
代码示例来源:origin: ReactiveX/RxJava
@Override
public void accept(Object v) throws Exception {
interrupted.set(Thread.currentThread().isInterrupted());
cdl.countDown();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public void run() throws Exception {
interrupted.set(Thread.currentThread().isInterrupted());
cdl.countDown();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onNext(Integer t) {
System.err.println("testSubscriber received => " + t + " on thread " + Thread.currentThread());
super.onNext(t);
}
};
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Subscriber<? super Integer> t1) {
subscribeThread.set(Thread.currentThread());
t1.onSubscribe(subscription);
t1.onNext(1);
t1.onNext(2);
// observeOn will prevent canceling the upstream upon its termination now
// this call is racing for that state in this test
// not doing it will make sure the unsubscribeOn always gets through
// t1.onComplete();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void interrupted() {
Iterator<Object> it = Observable.never().blockingLatest().iterator();
Thread.currentThread().interrupt();
try {
it.hasNext();
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
}
Thread.interrupted();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void interruptTestWaitStrategy() {
try {
Thread.currentThread().interrupt();
TestWaitStrategy.SLEEP_1000MS.run();
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void interrupt() {
Iterator<Object> it = Observable.never().blockingNext().iterator();
try {
Thread.currentThread().interrupt();
it.next();
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Observer<? super Integer> t1) {
subscribeThread.set(Thread.currentThread());
t1.onSubscribe(subscription);
t1.onNext(1);
t1.onNext(2);
// observeOn will prevent canceling the upstream upon its termination now
// this call is racing for that state in this test
// not doing it will make sure the unsubscribeOn always gets through
// t1.onComplete();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void interrupt() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L);
Thread.currentThread().interrupt();
try {
Flowable.just(1)
.blockingSubscribe(ts);
ts.assertFailure(InterruptedException.class);
} finally {
Thread.interrupted(); // clear interrupted status just in case
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void blockingFirstTimeout2() {
BlockingFirstSubscriber<Integer> bf = new BlockingFirstSubscriber<Integer>();
bf.onSubscribe(new BooleanSubscription());
Thread.currentThread().interrupt();
try {
bf.blockingGet();
fail("Should have thrown!");
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
}
}
内容来源于网络,如有侵权,请联系作者删除!