首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

利用递归算法并行弥合决谜题框架

2013-05-02 
利用递归算法并行化解决谜题框架public class PuzzleSolverP, M extends ConcurrentPuzzleSolverP, M

利用递归算法并行化解决谜题框架
public class PuzzleSolver<P, M> extends ConcurrentPuzzleSolver<P, M> { PuzzleSolver(Puzzle<P, M> puzzle) { super(puzzle); } private final AtomicInteger taskCount = new AtomicInteger(0); protected Runnable newTask(P p, M m, PuzzleNode<P, M> n) { return new CountingSolverTask(p, m, n); } class CountingSolverTask extends SolverTask { CountingSolverTask(P pos, M move, PuzzleNode<P, M> prev) { super(pos, move, prev); taskCount.incrementAndGet(); } public void run() { try { super.run(); } finally { if (taskCount.decrementAndGet() == 0) solution.setValue(null); } } }}

?

另外,还可以将ValueLatch设置为限时的,将getValue使用await的限时版实现,那么就可以指定多少时间内搜索结果,搜不到就超时中断。

热点排行