本文整理汇总了Java中java.util.concurrent.RecursiveAction类的典型用法代码示例。如果您正苦于以下问题:Java RecursiveAction类的具体用法?Java RecursiveAction怎么用?Java RecursiveAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RecursiveAction类属于java.util.concurrent包,在下文中一共展示了RecursiveAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPollNextLocalTask
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* pollNextLocalTask returns most recent unexecuted task without
* executing it
*/
public void testPollNextLocalTask() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib g = new AsyncFib(9);
assertSame(g, g.fork());
AsyncFib f = new AsyncFib(8);
assertSame(f, f.fork());
assertSame(f, pollNextLocalTask());
helpQuiesce();
checkNotDone(f);
assertEquals(34, g.number);
checkCompletedNormally(g);
}};
testInvokeOnPool(singletonPool(), a);
}
示例2: testAbnormalForkGet
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* get of a forked task throws exception when task completes abnormally
*/
public void testAbnormalForkGet() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FailingAsyncFib f = new FailingAsyncFib(8);
assertSame(f, f.fork());
try {
f.get();
shouldThrow();
} catch (ExecutionException success) {
Throwable cause = success.getCause();
assertTrue(cause instanceof FJException);
checkCompletedAbnormally(f, cause);
}
}};
testInvokeOnPool(mainPool(), a);
}
示例3: testAbnormalForkGet
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
public void testAbnormalForkGet(ForkJoinPool pool) {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FailingAsyncFib f = new FailingAsyncFib(8);
assertSame(f, f.fork());
try {
f.get();
shouldThrow();
} catch (ExecutionException success) {
Throwable cause = success.getCause();
assertTrue(cause instanceof FJException);
checkCompletedAbnormally(f, cause);
}
}};
testInvokeOnPool(pool, a);
}
示例4: testAbnormalInvokeAll2Singleton
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* invokeAll(t1, t2) throw exception if any task does
*/
public void testAbnormalInvokeAll2Singleton() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib f = new AsyncFib(8);
FailingAsyncFib g = new FailingAsyncFib(9);
ForkJoinTask[] tasks = { f, g };
shuffle(tasks);
try {
invokeAll(tasks);
shouldThrow();
} catch (FJException success) {
checkCompletedAbnormally(g, success);
}
}};
testInvokeOnPool(singletonPool(), a);
}
示例5: testCancelledForkJoinSingleton
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* join of a forked task throws exception when task cancelled
*/
public void testCancelledForkJoinSingleton() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib f = new AsyncFib(8);
assertTrue(f.cancel(true));
assertSame(f, f.fork());
try {
f.join();
shouldThrow();
} catch (CancellationException success) {
checkCancelled(f);
}
}};
testInvokeOnPool(singletonPool(), a);
}
示例6: testAbnormalInvokeAllCollectionSingleton
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* invokeAll(collection) throws exception if any task does
*/
public void testAbnormalInvokeAllCollectionSingleton() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
FailingAsyncFib f = new FailingAsyncFib(8);
AsyncFib g = new AsyncFib(9);
AsyncFib h = new AsyncFib(7);
ForkJoinTask[] tasks = { f, g, h };
shuffle(tasks);
try {
invokeAll(Arrays.asList(tasks));
shouldThrow();
} catch (FJException success) {
checkCompletedAbnormally(f, success);
}
}};
testInvokeOnPool(singletonPool(), a);
}
示例7: testAbnormalInvokeAll3
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* invokeAll(tasks) with > 2 argument throws exception if any task does
*/
public void testAbnormalInvokeAll3() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib f = new AsyncFib(8);
FailingAsyncFib g = new FailingAsyncFib(9);
AsyncFib h = new AsyncFib(7);
ForkJoinTask[] tasks = { f, g, h };
shuffle(tasks);
try {
invokeAll(tasks);
shouldThrow();
} catch (FJException success) {
checkCompletedAbnormally(g, success);
}
}};
testInvokeOnPool(mainPool(), a);
}
示例8: testAbnormalInvokeAll2
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
public void testAbnormalInvokeAll2(ForkJoinPool pool) {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib f = new AsyncFib(8);
FailingAsyncFib g = new FailingAsyncFib(9);
ForkJoinTask[] tasks = { f, g };
shuffle(tasks);
try {
invokeAll(tasks[0], tasks[1]);
shouldThrow();
} catch (FJException success) {
checkCompletedAbnormally(g, success);
}
}};
testInvokeOnPool(pool, a);
}
示例9: testCancelledForkJoin
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* join of a forked task throws exception when task cancelled
*/
public void testCancelledForkJoin() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib f = new AsyncFib(8);
assertTrue(f.cancel(true));
assertSame(f, f.fork());
try {
f.join();
shouldThrow();
} catch (CancellationException success) {
checkCancelled(f);
}
}};
testInvokeOnPool(mainPool(), a);
}
示例10: testGetSurplusQueuedTaskCount
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* getSurplusQueuedTaskCount returns > 0 when
* there are more tasks than threads
*/
public void testGetSurplusQueuedTaskCount() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib h = new AsyncFib(7);
assertSame(h, h.fork());
AsyncFib g = new AsyncFib(9);
assertSame(g, g.fork());
AsyncFib f = new AsyncFib(8);
assertSame(f, f.fork());
assertTrue(getSurplusQueuedTaskCount() > 0);
helpQuiesce();
assertEquals(0, getSurplusQueuedTaskCount());
f.checkCompletedNormally();
g.checkCompletedNormally();
h.checkCompletedNormally();
}};
testInvokeOnPool(singletonPool(), a);
}
示例11: testPeekNextLocalTask
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* peekNextLocalTask returns most recent unexecuted task.
*/
public void testPeekNextLocalTask() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib g = new AsyncFib(9);
assertSame(g, g.fork());
AsyncFib f = new AsyncFib(8);
assertSame(f, f.fork());
assertSame(f, peekNextLocalTask());
assertNull(f.join());
f.checkCompletedNormally();
helpQuiesce();
g.checkCompletedNormally();
}};
testInvokeOnPool(singletonPool(), a);
}
示例12: testPollNextLocalTaskAsync
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* pollNextLocalTask returns least recent unexecuted task without
* executing it, in async mode
*/
public void testPollNextLocalTaskAsync() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib g = new AsyncFib(9);
assertSame(g, g.fork());
AsyncFib f = new AsyncFib(8);
assertSame(f, f.fork());
assertSame(g, pollNextLocalTask());
helpQuiesce();
assertEquals(21, f.number);
checkCompletedNormally(f);
checkNotDone(g);
}};
testInvokeOnPool(asyncSingletonPool(), a);
}
示例13: testGetSurplusQueuedTaskCount
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* getSurplusQueuedTaskCount returns > 0 when
* there are more tasks than threads
*/
public void testGetSurplusQueuedTaskCount() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
FibAction h = new FibAction(7);
assertSame(h, h.fork());
FibAction g = new FibAction(9);
assertSame(g, g.fork());
FibAction f = new FibAction(8);
assertSame(f, f.fork());
assertTrue(getSurplusQueuedTaskCount() > 0);
helpQuiesce();
assertEquals(0, getSurplusQueuedTaskCount());
checkCompletedNormally(f);
checkCompletedNormally(g);
checkCompletedNormally(h);
}};
testInvokeOnPool(singletonPool(), a);
}
示例14: testCancelledForkTimedGetSingleton
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* timed get of a forked task throws exception when task cancelled
*/
public void testCancelledForkTimedGetSingleton() throws Exception {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
AsyncFib f = new AsyncFib(8);
assertTrue(f.cancel(true));
assertSame(f, f.fork());
try {
f.get(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (CancellationException success) {
checkCancelled(f);
}
}};
testInvokeOnPool(singletonPool(), a);
}
示例15: testAbnormalForkGet
import java.util.concurrent.RecursiveAction; //导入依赖的package包/类
/**
* get of a forked task throws exception when task completes abnormally
*/
public void testAbnormalForkGet() {
RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FailingFibAction f = new FailingFibAction(8);
assertSame(f, f.fork());
try {
f.get();
shouldThrow();
} catch (ExecutionException success) {
Throwable cause = success.getCause();
assertTrue(cause instanceof FJException);
checkCompletedAbnormally(f, cause);
}
}};
checkInvoke(a);
}