本文整理了Java中java.lang.Thread.join()
方法的一些代码示例,展示了Thread.join()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.join()
方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:join
[英]Waits for this thread to die.
An invocation of this method behaves in exactly the same way as the invocation
#join(long) (0)
[中]等待此线程死亡。
此方法的调用与调用的行为方式完全相同
#连接(长)(0)
代码示例来源:origin: ReactiveX/RxJava
public void waitToFinish() {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: ReactiveX/RxJava
public void waitToFinish() {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: ReactiveX/RxJava
public void waitToFinish() {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: ReactiveX/RxJava
public void waitToFinish() {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: ReactiveX/RxJava
void waitForThreadDone() throws InterruptedException {
threadHasStarted.await();
t.join();
}
}
代码示例来源:origin: ReactiveX/RxJava
public void waitToFinish() {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: ReactiveX/RxJava
public void waitToFinish() {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: ReactiveX/RxJava
public void waitToFinish() {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: ReactiveX/RxJava
void waitForThreadDone() throws InterruptedException {
threadHasStarted.await();
t.join();
}
}
代码示例来源:origin: ReactiveX/RxJava
public void waitToFinish() {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: google/guava
synchronized void shutdown() throws InterruptedException {
for (Thread hook : hooks) {
hook.start();
}
for (Thread hook : hooks) {
hook.join();
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testMergeArrayWithThreading() {
final TestASynchronousObservable o1 = new TestASynchronousObservable();
final TestASynchronousObservable o2 = new TestASynchronousObservable();
Observable<String> m = Observable.mergeDelayError(Observable.unsafeCreate(o1), Observable.unsafeCreate(o2));
m.subscribe(stringObserver);
try {
o1.t.join();
o2.t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
verify(stringObserver, never()).onError(any(Throwable.class));
verify(stringObserver, times(2)).onNext("hello");
verify(stringObserver, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testMergeArrayWithThreading() {
final TestASynchronousFlowable f1 = new TestASynchronousFlowable();
final TestASynchronousFlowable f2 = new TestASynchronousFlowable();
Flowable<String> m = Flowable.mergeDelayError(Flowable.unsafeCreate(f1), Flowable.unsafeCreate(f2));
m.subscribe(stringSubscriber);
try {
f1.t.join();
f2.t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
verify(stringSubscriber, never()).onError(any(Throwable.class));
verify(stringSubscriber, times(2)).onNext("hello");
verify(stringSubscriber, times(1)).onComplete();
}
代码示例来源:origin: google/guava
public void testJoinWithNoWait() throws InterruptedException {
Stopwatch stopwatch = Stopwatch.createStarted();
Thread thread = new Thread(new JoinTarget(15));
thread.start();
thread.join();
assertFalse(thread.isAlive());
joinUninterruptibly(thread);
joinUninterruptibly(thread, 0, MILLISECONDS);
joinUninterruptibly(thread, -42, MILLISECONDS);
joinUninterruptibly(thread, LONG_DELAY_MS, MILLISECONDS);
assertTimeNotPassed(stopwatch, LONG_DELAY_MS);
}
代码示例来源:origin: google/guava
public void testServiceThrowOnShutDown() throws Exception {
ThrowOnShutDown service = new ThrowOnShutDown();
service.startAsync().awaitRunning();
assertEquals(Service.State.RUNNING, service.state());
service.stopAsync();
enterRun.countDown();
executionThread.join();
assertEquals(Service.State.FAILED, service.state());
assertThat(service.failureCause()).hasMessageThat().isEqualTo("kaboom!");
}
代码示例来源:origin: google/guava
public void testServiceThrowOnRun() throws Exception {
ThrowOnRunService service = new ThrowOnRunService();
service.startAsync();
try {
service.awaitTerminated();
fail();
} catch (IllegalStateException expected) {
executionThread.join();
assertThat(expected).hasCauseThat().isEqualTo(service.failureCause());
assertThat(expected).hasCauseThat().hasMessageThat().isEqualTo("kaboom!");
}
assertTrue(service.shutDownCalled);
assertEquals(Service.State.FAILED, service.state());
}
代码示例来源:origin: google/guava
public void testServiceStartStop() throws Exception {
WaitOnRunService service = new WaitOnRunService();
assertFalse(service.startUpCalled);
service.startAsync().awaitRunning();
assertTrue(service.startUpCalled);
assertEquals(Service.State.RUNNING, service.state());
enterRun.await(); // to avoid stopping the service until run() is invoked
service.stopAsync().awaitTerminated();
assertTrue(service.shutDownCalled);
assertEquals(Service.State.TERMINATED, service.state());
executionThread.join();
}
代码示例来源:origin: google/guava
public void testServiceStopIdempotence() throws Exception {
WaitOnRunService service = new WaitOnRunService();
service.startAsync().awaitRunning();
enterRun.await(); // to avoid stopping the service until run() is invoked
service.stopAsync();
service.stopAsync();
service.stopAsync().awaitTerminated();
assertEquals(Service.State.TERMINATED, service.state());
service.stopAsync().awaitTerminated();
assertEquals(Service.State.TERMINATED, service.state());
executionThread.join();
}
代码示例来源:origin: google/guava
public void testServiceExitingOnItsOwn() throws Exception {
WaitOnRunService service = new WaitOnRunService();
service.expectedShutdownState = Service.State.RUNNING;
service.startAsync().awaitRunning();
assertTrue(service.startUpCalled);
assertEquals(Service.State.RUNNING, service.state());
exitRun.countDown(); // the service will exit voluntarily
executionThread.join();
assertTrue(service.shutDownCalled);
assertEquals(Service.State.TERMINATED, service.state());
service.stopAsync().awaitTerminated(); // no-op
assertEquals(Service.State.TERMINATED, service.state());
assertTrue(service.shutDownCalled);
}
代码示例来源:origin: google/guava
public void testThreadedServiceStopIdempotenceAfterWait() throws Throwable {
ThreadedService service = new ThreadedService();
service.startAsync().awaitRunning();
assertEquals(State.RUNNING, service.state());
service.awaitRunChecks();
service.stopAsync().awaitTerminated();
service.stopAsync();
assertEquals(State.TERMINATED, service.state());
executionThread.join();
throwIfSet(thrownByExecutionThread);
}
内容来源于网络,如有侵权,请联系作者删除!