我正在研究一些代码,这是一种方法,我不太确定它的作用:
1)有一个RunnableFuture
,为什么分配一个FutureTask
,为什么不FutureTask = new Futuretask
?
2) 是什么意思new SortProcessor<E>
,是来自Java还是其他类。
public synchronized void sort() {
if (this.internalState == InternalState.READ) throw new IllegalStateException();
final RunnableFuture<E> leftFuture = new FutureTask<E>(new SortProcessor<E>(this.leftChild));
final RunnableFuture<E> rightFuture = new FutureTask<E>(new SortProcessor<E>(this.rightChild));
new Thread(leftFuture, "left-child").start();
new Thread(rightFuture, "right-child").start();
try {
this.leftCache = leftFuture.get();
this.rightCache = rightFuture.get();
} catch (final InterruptedException interrupt) {
throw new ThreadDeath();
} catch (final ExecutionException exception) {
final Throwable cause = exception.getCause();
if (cause instanceof Error) throw (Error) cause;
if (cause instanceof RuntimeException) throw (RuntimeException) cause;
throw new AssertionError();
}
if (this.leftCache != null | this.rightCache != null) {
this.internalState = InternalState.READ;
}
}