本文整理了Java中java.util.concurrent.FutureTask.<init>()
方法的一些代码示例,展示了FutureTask.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FutureTask.<init>()
方法的具体详情如下:
包路径:java.util.concurrent.FutureTask
类名称:FutureTask
方法名:<init>
[英]Creates a FutureTask that will, upon running, execute the given Runnable, and arrange that get will return the given result on successful completion.
[中]创建一个FutureTask,该任务将在运行时执行给定的Runnable,并安排get在成功完成时返回给定的结果。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Long> createPublisher(final long elements) {
FutureTask<Long> ft = new FutureTask<Long>(new Callable<Long>() {
@Override
public Long call() throws Exception {
return 1L;
}
});
ft.run();
return Flowable.fromFuture(ft);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromFutureTimedUnitNull() {
Single.fromFuture(new FutureTask<Object>(new Callable<Object>() {
@Override
public Object call() throws Exception {
return null;
}
}), 1, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromFutureSchedulerNull() {
Single.fromFuture(new FutureTask<Object>(new Callable<Object>() {
@Override
public Object call() throws Exception {
return null;
}
}), null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromFutureSchedulerNull() {
FutureTask<Object> f = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
Observable.fromFuture(f, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromFutureTimedSchedulerNull() {
Single.fromFuture(new FutureTask<Object>(new Callable<Object>() {
@Override
public Object call() throws Exception {
return null;
}
}), 1, TimeUnit.SECONDS, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromFutureReturnsNull() {
FutureTask<Object> f = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
f.run();
Single.fromFuture(f).blockingGet();
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromFutureTimedReturnsNull() {
FutureTask<Object> f = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
f.run();
Single.fromFuture(f, 1, TimeUnit.SECONDS).blockingGet();
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromFutureTimedReturnsNull() {
FutureTask<Object> f = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
f.run();
Flowable.fromFuture(f, 1, TimeUnit.SECONDS).blockingLast();
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromFutureTimedReturnsNull() {
FutureTask<Object> f = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
f.run();
Observable.fromFuture(f, 1, TimeUnit.SECONDS).blockingLast();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void interrupt() {
FutureTask<Integer> ft = new FutureTask<Integer>(Functions.justCallable(1));
Thread.currentThread().interrupt();
Maybe.fromFuture(ft, 1, TimeUnit.MILLISECONDS).test()
.assertFailure(InterruptedException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fromFutureReturnsNull() {
FutureTask<Object> f = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
f.run();
TestObserver<Object> to = new TestObserver<Object>();
Observable.fromFuture(f).subscribe(to);
to.assertNoValues();
to.assertNotComplete();
to.assertError(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timedWait() {
FutureTask<Integer> ft = new FutureTask<Integer>(Functions.justCallable(1));
ft.run();
Maybe.fromFuture(ft, 1, TimeUnit.MILLISECONDS).test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fromFutureReturnsNull() {
FutureTask<Object> f = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
f.run();
TestSubscriber<Object> ts = new TestSubscriber<Object>();
Flowable.fromFuture(f).subscribe(ts);
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void cancelImmediately() {
FutureTask<Integer> ft = new FutureTask<Integer>(Functions.justCallable(1));
Maybe.fromFuture(ft).test(true)
.assertEmpty();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void withFutureDisposed() {
ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, null);
run.setFuture(new FutureTask<Void>(Functions.EMPTY_RUNNABLE, null));
run.dispose();
run.call();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void withFutureDisposed2() {
ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, null);
run.dispose();
run.setFuture(new FutureTask<Void>(Functions.EMPTY_RUNNABLE, null));
run.call();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normal() {
FutureTask<Object> ft = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
Disposable d = Disposables.fromFuture(ft);
assertFalse(d.isDisposed());
d.dispose();
assertTrue(d.isDisposed());
d.dispose();
assertTrue(d.isDisposed());
assertTrue(ft.isCancelled());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void interruptible() {
FutureTask<Object> ft = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
Disposable d = Disposables.fromFuture(ft, true);
assertFalse(d.isDisposed());
d.dispose();
assertTrue(d.isDisposed());
d.dispose();
assertTrue(d.isDisposed());
assertTrue(ft.isCancelled());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalDone() {
FutureTask<Object> ft = new FutureTask<Object>(Functions.EMPTY_RUNNABLE, null);
FutureDisposable d = new FutureDisposable(ft, false);
assertFalse(d.isDisposed());
assertFalse(d.isDisposed());
ft.run();
assertTrue(d.isDisposed());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timeout() {
FutureTask<Integer> ft = new FutureTask<Integer>(Functions.justCallable(1));
Maybe.fromFuture(ft, 1, TimeUnit.MILLISECONDS).test()
.awaitDone(5, TimeUnit.SECONDS)
.assertFailure(TimeoutException.class);
}
内容来源于网络,如有侵权,请联系作者删除!