/** * @param file * @return * @throws PMDException * @throws InterruptedException * @throws ExecutionException */ public static IParserNode buildThreadedAst(final IFlexFile file) throws PMDException, InterruptedException, ExecutionException { final List<Callable<Object>> toRun = new ArrayList<Callable<Object>>(); toRun.add( new Callable<Object>() { public Object call() throws PMDException { return buildAst(file); } }); final List<Future<Object>> futures = EXECUTOR.invokeAll(toRun, 5, TimeUnit.SECONDS); return (IParserNode) futures.get(0).get(); }
@Test public void testCountDown() { List<TestRunnable> tasks = Lists.newArrayList(); TestRunnable r = new TestRunnable(counter); for (int i = 0; i < 10000; i++) { tasks.add(r); } try { pool.invokeAll(tasks); } catch (InterruptedException e) { throw Throwables.propagate(e); } }
/** Build the weight table, parallelized according to the number of processors */ public void buildTable() { ArrayList<TransitStop> stopVertices; LOG.debug("Number of vertices: " + g.getVertices().size()); stopVertices = new ArrayList<TransitStop>(); for (Vertex gv : g.getVertices()) if (gv instanceof TransitStop) stopVertices.add((TransitStop) gv); int nStops = stopVertices.size(); stopIndices = new IdentityHashMap<Vertex, Integer>(nStops); for (int i = 0; i < nStops; i++) stopIndices.put(stopVertices.get(i), i); LOG.debug("Number of stops: " + nStops); table = new float[nStops][nStops]; for (float[] row : table) Arrays.fill(row, Float.POSITIVE_INFINITY); LOG.debug("Performing search at each transit stop."); int nThreads = Runtime.getRuntime().availableProcessors(); LOG.debug("number of threads: " + nThreads); ArrayBlockingQueue<Runnable> taskQueue = new ArrayBlockingQueue<Runnable>(nStops); ThreadPoolExecutor threadPool = new ThreadPoolExecutor(nThreads, nThreads, 10, TimeUnit.SECONDS, taskQueue); GenericObjectPool heapPool = new GenericObjectPool(new PoolableBinHeapFactory<State>(g.getVertices().size()), nThreads); // make one heap and recycle it TraverseOptions options = new TraverseOptions(); options.speed = maxWalkSpeed; final double MAX_WEIGHT = 60 * 60 * options.walkReluctance; final double OPTIMISTIC_BOARD_COST = options.boardCost; // create a task for each transit stop in the graph ArrayList<Callable<Void>> tasks = new ArrayList<Callable<Void>>(); for (TransitStop origin : stopVertices) { SPTComputer task = new SPTComputer(heapPool, options, MAX_WEIGHT, OPTIMISTIC_BOARD_COST, origin); tasks.add(task); } try { // invoke all of tasks. threadPool.invokeAll(tasks); threadPool.shutdown(); } catch (InterruptedException e) { throw new RuntimeException(e); } floyd(); }
public <T> List<Future<T>> invokeAll( Collection<? extends Callable<T>> callable, long timeout, TimeUnit unit) throws InterruptedException { return executorService_.invokeAll(callable, timeout, unit); }
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> callable) throws InterruptedException { return executorService_.invokeAll(callable); }