private static void Pause(String description) throws Exception { Singletons.Log.Debug( "Pausing for " + Settings.PAUSE_SECONDS + " seconds: " + description + ". Other threads may be processing these tasks."); MiscUtilities.Sleep(Settings.PAUSE_SECONDS * 1000); Singletons.Log.Debug("Done with pause: " + description + "."); }
/** * Executes multiple callable objects in a multithreaded fashion * * @return Objects that are returned from each _callable object * @throws Exception */ public ArrayList Execute() throws Exception { if (_callables == null || _callables.size() == 0) return new ArrayList(); Singletons.Log.Debug( "Attempting to share execution across " + _numThreads + " threads for " + _description + "."); // Initialize the service // ExecutorService service = Executors.newFixedThreadPool(_numThreads); ExecutorService service = new TimeoutThreadPoolExecutor(_numThreads); try { ArrayList<Future<Object>> futures = new ArrayList<Future<Object>>(); // Submit each task to a queue to be executed for (Callable<Object> callable : _callables) futures.add(service.submit(callable)); ArrayList results = new ArrayList(); // Parse through the results of the execution for (Future<Object> future : futures) { Object result = future.get(); if (result != null) results.add(result); } return results; } catch (Exception ex) { throw ex; } finally { // Very important to shut down the service service.shutdown(); } }