本文整理了Java中java.lang.Thread.start()
方法的一些代码示例,展示了Thread.start()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.start()
方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:start
[英]Causes this thread to begin execution; the Java Virtual Machine calls the run
method of this thread.
The result is that two threads are running concurrently: the current thread (which returns from the call to the start
method) and the other thread (which executes its run
method).
It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.
[中]使该线程开始执行;Java虚拟机调用此线程的run
方法。
结果是两个线程同时运行:当前线程(从调用start
方法返回)和另一个线程(执行run
方法)。
多次启动线程是不合法的。特别是,线程一旦完成执行,就不能重新启动。
代码示例来源:origin: ReactiveX/RxJava
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
}, true);
代码示例来源:origin: ReactiveX/RxJava
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
}, true);
代码示例来源:origin: ReactiveX/RxJava
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
}, true);
代码示例来源:origin: ReactiveX/RxJava
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
});
代码示例来源:origin: google/guava
@Override
public void execute(Runnable command) {
MoreExecutors.newThread(serviceName(), command).start();
}
};
代码示例来源:origin: google/guava
/** Returns a new started daemon Thread running the given runnable. */
Thread newStartedThread(Runnable runnable) {
Thread t = new Thread(runnable);
t.setDaemon(true);
t.start();
return t;
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(final Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
subscriber.onNext("one");
subscriber.onComplete();
}
}).start();
}
}).publish();
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(final Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
subscriber.onNext("one");
subscriber.onComplete();
}
}).start();
}
}).cacheWithInitialCapacity(1);
代码示例来源:origin: google/guava
private static void scheduleEnableWrites(BlockingQueue<String> queue, long countdownInMillis) {
Runnable toRun = new EnableWrites(queue, countdownInMillis);
// TODO(cpovirk): automatically fail the test if this thread throws
Thread enablerThread = new Thread(toRun);
enablerThread.start();
}
}
代码示例来源:origin: google/guava
private static void scheduleEnableReads(BlockingQueue<String> queue, long countdownInMillis) {
Runnable toRun = new EnableReads(queue, countdownInMillis);
// TODO(cpovirk): automatically fail the test if this thread throws
Thread enablerThread = new Thread(toRun);
enablerThread.start();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(final Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
t = new Thread(new Runnable() {
@Override
public void run() {
subscriber.onNext("hello");
subscriber.onComplete();
}
});
t.start();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(final Observer<? super String> observer) {
observer.onSubscribe(Disposables.empty());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
observer.onNext("one");
observer.onComplete();
}
}).start();
}
}).replay();
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(final Observer<? super String> observer) {
observer.onSubscribe(Disposables.empty());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
observer.onNext("one");
observer.onComplete();
}
}).start();
}
}).publish();
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(final Observer<? super String> observer) {
observer.onSubscribe(Disposables.empty());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
observer.onNext("one");
observer.onComplete();
}
}).start();
}
}).cache();
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(final Observer<? super String> observer) {
observer.onSubscribe(Disposables.empty());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
observer.onNext("one");
observer.onComplete();
}
}).start();
}
}).cacheWithInitialCapacity(1);
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(final Observer<? super String> observer) {
observer.onSubscribe(Disposables.empty());
t = new Thread(new Runnable() {
@Override
public void run() {
observer.onNext("hello");
observer.onComplete();
}
});
t.start();
}
}
代码示例来源:origin: google/guava
private TimedThread(long expectedCompletionWaitMillis) {
completed = new Completion(expectedCompletionWaitMillis);
thread = new Thread(new JoinTarget(expectedCompletionWaitMillis));
thread.start();
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!