90 |
|
void checkIsRunning(Future<?> f) { |
91 |
|
checkNotDone(f); |
92 |
|
if (f instanceof FutureTask) { |
93 |
< |
FutureTask ft = (FutureTask<?>) f; |
93 |
> |
FutureTask<?> ft = (FutureTask<?>) f; |
94 |
|
// Check that run methods do nothing |
95 |
|
ft.run(); |
96 |
|
if (f instanceof PublicFutureTask) { |
164 |
|
/** |
165 |
|
* Subclass to expose protected methods |
166 |
|
*/ |
167 |
< |
static class PublicFutureTask extends FutureTask { |
167 |
> |
static class PublicFutureTask extends FutureTask<Object> { |
168 |
|
private final AtomicInteger runCount; |
169 |
|
private final AtomicInteger doneCount = new AtomicInteger(0); |
170 |
|
private final AtomicInteger runAndResetCount = new AtomicInteger(0); |
191 |
|
}}, result); |
192 |
|
this.runCount = runCount; |
193 |
|
} |
194 |
< |
PublicFutureTask(Callable callable) { |
194 |
> |
PublicFutureTask(Callable<?> callable) { |
195 |
|
this(callable, new AtomicInteger(0)); |
196 |
|
} |
197 |
< |
private PublicFutureTask(final Callable callable, |
197 |
> |
private PublicFutureTask(final Callable<?> callable, |
198 |
|
final AtomicInteger runCount) { |
199 |
< |
super(new Callable() { |
199 |
> |
super(new Callable<Object>() { |
200 |
|
public Object call() throws Exception { |
201 |
|
runCount.getAndIncrement(); |
202 |
|
return callable.call(); |
235 |
|
*/ |
236 |
|
public void testConstructor() { |
237 |
|
try { |
238 |
< |
new FutureTask(null); |
238 |
> |
new FutureTask<Void>(null); |
239 |
|
shouldThrow(); |
240 |
|
} catch (NullPointerException success) {} |
241 |
|
} |
245 |
|
*/ |
246 |
|
public void testConstructor2() { |
247 |
|
try { |
248 |
< |
new FutureTask(null, Boolean.TRUE); |
248 |
> |
new FutureTask<Boolean>(null, Boolean.TRUE); |
249 |
|
shouldThrow(); |
250 |
|
} catch (NullPointerException success) {} |
251 |
|
} |
677 |
|
*/ |
678 |
|
public void testGet_ExecutionException() throws InterruptedException { |
679 |
|
final ArithmeticException e = new ArithmeticException(); |
680 |
< |
final PublicFutureTask task = new PublicFutureTask(new Callable() { |
680 |
> |
final PublicFutureTask task = new PublicFutureTask(new Callable<Object>() { |
681 |
|
public Object call() { |
682 |
|
throw e; |
683 |
|
}}); |
701 |
|
*/ |
702 |
|
public void testTimedGet_ExecutionException2() throws Exception { |
703 |
|
final ArithmeticException e = new ArithmeticException(); |
704 |
< |
final PublicFutureTask task = new PublicFutureTask(new Callable() { |
704 |
> |
final PublicFutureTask task = new PublicFutureTask(new Callable<Object>() { |
705 |
|
public Object call() { |
706 |
|
throw e; |
707 |
|
}}); |
722 |
|
*/ |
723 |
|
public void testGet_Interruptible() { |
724 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
725 |
< |
final FutureTask task = new FutureTask(new NoOpCallable()); |
725 |
> |
final FutureTask<Object> task = new FutureTask<Object>(new NoOpCallable()); |
726 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
727 |
|
public void realRun() throws Exception { |
728 |
|
Thread.currentThread().interrupt(); |
751 |
|
*/ |
752 |
|
public void testTimedGet_Interruptible() { |
753 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
754 |
< |
final FutureTask task = new FutureTask(new NoOpCallable()); |
754 |
> |
final FutureTask<Object> task = new FutureTask<Object>(new NoOpCallable()); |
755 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
756 |
|
public void realRun() throws Exception { |
757 |
|
Thread.currentThread().interrupt(); |
780 |
|
* A timed out timed get throws TimeoutException |
781 |
|
*/ |
782 |
|
public void testGet_TimeoutException() throws Exception { |
783 |
< |
FutureTask task = new FutureTask(new NoOpCallable()); |
783 |
> |
FutureTask<Object> task = new FutureTask<Object>(new NoOpCallable()); |
784 |
|
long startTime = System.nanoTime(); |
785 |
|
try { |
786 |
|
task.get(timeoutMillis(), MILLISECONDS); |
794 |
|
* timed get with null TimeUnit throws NullPointerException |
795 |
|
*/ |
796 |
|
public void testGet_NullTimeUnit() throws Exception { |
797 |
< |
FutureTask task = new FutureTask(new NoOpCallable()); |
797 |
> |
FutureTask<Object> task = new FutureTask<Object>(new NoOpCallable()); |
798 |
|
long[] timeouts = { Long.MIN_VALUE, 0L, Long.MAX_VALUE }; |
799 |
|
|
800 |
|
for (long timeout : timeouts) { |