[url=http://www.ibm.com/developerworks/java/library/j-jtp11137.html]Java theory and practice: Stick a fork in it[/url]
[quote]One of the additions to the java.util.concurrent packages coming in Java™ 7 is a framework for fork-join style parallel decomposition. The fork-join abstraction provides a natural mechanism for decomposing many algorithms to effectively exploit hardware parallelism.[/quote]
汗...
Java 7不愧是kitchen-sink...不过这东西看起来又挺实用的,有些时候虽然觉得(在多处理器/多核心环境下)有些地方应该开多线程来做,不过要自己管理那么多东西也确实怪麻烦的。看一例子:
[quote]Listing 3. Solving the select-max problem with the fork-join framework
不过这东西要是能配合匿名方法/闭包来做就更简洁了。
话说,[url=http://www.third-bit.com/~gvwilson]Greg Wilson[/url]很明显对这东西[url=http://pyre.third-bit.com/blog/archives/1222.html]不感冒[/url]。一提到调试器,这并行计算的痛处就又来了一个……
[quote]One of the additions to the java.util.concurrent packages coming in Java™ 7 is a framework for fork-join style parallel decomposition. The fork-join abstraction provides a natural mechanism for decomposing many algorithms to effectively exploit hardware parallelism.[/quote]
汗...
Java 7不愧是kitchen-sink...不过这东西看起来又挺实用的,有些时候虽然觉得(在多处理器/多核心环境下)有些地方应该开多线程来做,不过要自己管理那么多东西也确实怪麻烦的。看一例子:
[quote]Listing 3. Solving the select-max problem with the fork-join framework
public class MaxWithFJ extends RecursiveAction {
private final int threshold;
private final SelectMaxProblem problem;
public int result;
public MaxWithFJ(SelectMaxProblem problem, int threshold) {
this.problem = problem;
this.threshold = threshold;
}
protected void compute() {
if (problem.size < threshold)
result = problem.solveSequentially();
else {
int midpoint = problem.size / 2;
MaxWithFJ left = new MaxWithFJ(problem.subproblem(0, midpoint), threshold);
MaxWithFJ right = new MaxWithFJ(problem.subproblem(midpoint +
1, problem.size), threshold);
coInvoke(left, right);
result = Math.max(left.result, right.result);
}
}
public static void main(String[] args) {
SelectMaxProblem problem = ...
int threshold = ...
int nThreads = ...
MaxWithFJ mfj = new MaxWithFJ(problem, threshold);
ForkJoinExecutor fjPool = new ForkJoinPool(nThreads);
fjPool.invoke(mfj);
int result = mfj.result;
}
}
[/quote]
不过这东西要是能配合匿名方法/闭包来做就更简洁了。
话说,[url=http://www.third-bit.com/~gvwilson]Greg Wilson[/url]很明显对这东西[url=http://pyre.third-bit.com/blog/archives/1222.html]不感冒[/url]。一提到调试器,这并行计算的痛处就又来了一个……