本文整理了Java中java.util.concurrent.ForkJoinPool.invoke()
方法的一些代码示例,展示了ForkJoinPool.invoke()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ForkJoinPool.invoke()
方法的具体详情如下:
包路径:java.util.concurrent.ForkJoinPool
类名称:ForkJoinPool
方法名:invoke
[英]Performs the given task, returning its result upon completion. If the computation encounters an unchecked Exception or Error, it is rethrown as the outcome of this invocation. Rethrown exceptions behave in the same way as regular exceptions, but, when possible, contain stack traces (as displayed for example using ex.printStackTrace()) of both the current thread as well as the thread actually encountering the exception; minimally only the latter.
[中]执行给定任务,完成后返回其结果。如果计算遇到未经检查的异常或错误,它将作为此调用的结果重新调用。Rethrown异常的行为方式与常规异常相同,但在可能的情况下,包含当前线程以及实际遇到异常的线程的堆栈跟踪(例如使用ex.printStackTrace()显示);至少是后者。
代码示例来源:origin: lenskit/lenskit
private void runJobGraph(int nthreads) {
Preconditions.checkState(rootJob != null, "job graph not built");
ForkJoinPool pool = new ForkJoinPool(nthreads);
try {
pool.invoke(rootJob);
} catch (Throwable err) {
logger.error("experiment failed", err);
if (!continueAfterError) {
Throwables.throwIfUnchecked(err);
// will only happen if an undeclared checked exception slips through
throw new UncheckedExecutionException(err);
}
} finally {
pool.shutdown();
}
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
forkJoinPool.invoke(
new RecursiveRebuildTreeTask(
treeModelTasks, companyId, parentPrimaryKey,
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
forkJoinPool.invoke(
new RecursiveRebuildTreeTask(
treeModelTasks, companyId, parentPrimaryKey,
代码示例来源:origin: lenskit/lenskit
@Test
public void testAcquireSem() {
Semaphore sem = new Semaphore(2);
ForkJoinPool.commonPool().invoke(new RecursiveAction() {
AtomicInteger running = new AtomicInteger();
代码示例来源:origin: lenskit/lenskit
@Test
public void testAcquireMonitor() {
Monitor monitor = new Monitor();
ForkJoinPool.commonPool().invoke(new RecursiveAction() {
AtomicInteger running = new AtomicInteger();
代码示例来源:origin: inspectIT/inspectIT
/**
* {@inheritDoc}
*/
@Override
public List<IStorageDescriptor> query(IIndexQuery query, ForkJoinPool forkJoinPool) {
return forkJoinPool.invoke(getTaskForForkJoinQuery(query));
}
代码示例来源:origin: inspectIT/inspectIT
/**
* {@inheritDoc}
*/
@Override
public List<IStorageDescriptor> query(IIndexQuery query, ForkJoinPool forkJoinPool) {
return forkJoinPool.invoke(getTaskForForkJoinQuery(query));
}
代码示例来源:origin: inspectIT/inspectIT
/**
* {@inheritDoc}
*/
@Override
public List<E> query(IIndexQuery query, ForkJoinPool forkJoinPool) {
return forkJoinPool.invoke(getTaskForForkJoinQuery(query));
}
代码示例来源:origin: inspectIT/inspectIT
/**
* {@inheritDoc}
*/
@Override
public List<IStorageDescriptor> query(IIndexQuery query, ForkJoinPool forkJoinPool) {
return forkJoinPool.invoke(getTaskForForkJoinQuery(query));
}
代码示例来源:origin: inspectIT/inspectIT
/**
* {@inheritDoc}
*/
@Override
public List<R> query(IIndexQuery query, ForkJoinPool forkJoinPool) {
return forkJoinPool.invoke(getTaskForForkJoinQuery(query));
}
代码示例来源:origin: lejon/T-SNE-Java
public double[][] parScalarMinus(double [][] m1,double [][] m2) {
int ll = 600;
double [][] result = new double[m1.length][m1[0].length];
MatrixOperator process = new MatrixOperator(m1,m2,result, minusop, 0, m1.length,ll);
pool.invoke(process);
return result;
}
代码示例来源:origin: lejon/T-SNE-Java
@Override
void updateGradient(int N, int no_dims, double[] Y, double momentum, double eta, double[] dY, double[] uY,
double[] gains) {
RecursiveGradientUpdater dslr = new RecursiveGradientUpdater(N, no_dims, Y, momentum, eta, dY, uY, gains,0,N * no_dims,N/(Runtime.getRuntime().availableProcessors()*10));
gradientPool.invoke(dslr);
}
代码示例来源:origin: neo4j-contrib/neo4j-graph-algorithms
@Override
void runCompute() {
ForkJoinTask<Long> countTask = graph instanceof HugeGraph
? new HugeTask((HugeGraph) graph, 0, nodeCount)
: new TriangleTask(0, nodeCount);
triangleCount = pool.invoke(countTask);
CoefficientTask coefficientTask = new CoefficientTask(
Direction.OUTGOING,
0,
nodeCount);
averageClusteringCoefficient = pool.invoke(coefficientTask);
}
代码示例来源:origin: neo4j-contrib/neo4j-graph-algorithms
public DisjointSetStruct compute(double threshold) {
return ForkJoinPool
.commonPool()
.invoke(new ThresholdUFTask(0, threshold));
}
代码示例来源:origin: neo4j-contrib/neo4j-graph-algorithms
public PagedDisjointSetStruct compute(double threshold) {
return ForkJoinPool
.commonPool()
.invoke(new ThresholdUFTask(0, threshold));
}
代码示例来源:origin: org.neo4j/graph-algorithms-algo
public DisjointSetStruct compute(double threshold) {
return ForkJoinPool
.commonPool()
.invoke(new ThresholdUFTask(0, threshold));
}
代码示例来源:origin: neo4j-contrib/neo4j-graph-algorithms
public void merge(ArrayList<? extends UFProcess> ufProcesses) {
ParallelUtil.run(ufProcesses, executor);
if (!running()) {
return;
}
final Stack<DisjointSetStruct> temp = new Stack<>();
ufProcesses.forEach(uf -> temp.add(uf.struct));
struct = ForkJoinPool.commonPool().invoke(new Merge(temp));
}
代码示例来源:origin: neo4j-contrib/neo4j-graph-algorithms
private void merge(Collection<? extends UFTask> ufProcesses) {
ParallelUtil.run(ufProcesses, executor);
if (!running()) {
return;
}
final Stack<PagedDisjointSetStruct> temp = new Stack<>();
ufProcesses.forEach(uf -> temp.add(uf.struct()));
struct = ForkJoinPool.commonPool().invoke(new Merge(temp));
}
代码示例来源:origin: org.neo4j/graph-algorithms-algo
private void merge(Collection<? extends UFTask> ufProcesses) {
ParallelUtil.run(ufProcesses, executor);
if (!running()) {
return;
}
final Stack<PagedDisjointSetStruct> temp = new Stack<>();
ufProcesses.forEach(uf -> temp.add(uf.struct()));
struct = ForkJoinPool.commonPool().invoke(new Merge(temp));
}
代码示例来源:origin: zavtech/morpheus-core
@Override
public int count(Predicate<ArrayValue<T>> predicate) {
if (isParallel() && length() > 0) {
final int processors = Runtime.getRuntime().availableProcessors();
final int splitThreshold = Math.max(length() / processors, 10000);
return ForkJoinPool.commonPool().invoke(new CountTask<>(this, 0, length()-1, splitThreshold, predicate));
} else {
final CountTask task = new CountTask<>(this, 0, length()-1, Integer.MAX_VALUE, predicate);
return task.compute();
}
}
内容来源于网络,如有侵权,请联系作者删除!