List of usage examples for java.util.concurrent Executor execute
void execute(Runnable command);
From source file:com.samczsun.helios.bootloader.Bootloader.java
public static void main(String[] args) { try {/*from w w w.j a v a 2 s .c om*/ if (!Constants.DATA_DIR.exists() && !Constants.DATA_DIR.mkdirs()) throw new RuntimeException("Could not create data directory"); if (!Constants.ADDONS_DIR.exists() && !Constants.ADDONS_DIR.mkdirs()) throw new RuntimeException("Could not create addons directory"); if (!Constants.SETTINGS_FILE.exists() && !Constants.SETTINGS_FILE.createNewFile()) throw new RuntimeException("Could not create settings file"); if (Constants.DATA_DIR.isFile()) throw new RuntimeException("Data directory is file"); if (Constants.ADDONS_DIR.isFile()) throw new RuntimeException("Addons directory is file"); if (Constants.SETTINGS_FILE.isDirectory()) throw new RuntimeException("Settings file is directory"); loadSWTLibrary(); DisplayPumper displayPumper = new DisplayPumper(); if (System.getProperty("os.name").toLowerCase().contains("mac")) { System.out.println("Attemting to force main thread"); Executor executor; try { Class<?> dispatchClass = Class.forName("com.apple.concurrent.Dispatch"); Object dispatchInstance = dispatchClass.getMethod("getInstance").invoke(null); executor = (Executor) dispatchClass.getMethod("getNonBlockingMainQueueExecutor") .invoke(dispatchInstance); } catch (Throwable throwable) { throw new RuntimeException("Could not reflectively access Dispatch", throwable); } if (executor != null) { executor.execute(displayPumper); } else { throw new RuntimeException("Could not load executor"); } } else { Thread pumpThread = new Thread(displayPumper); pumpThread.start(); } while (!displayPumper.isReady()) ; Display display = displayPumper.getDisplay(); Shell shell = displayPumper.getShell(); Splash splashScreen = new Splash(display); splashScreen.updateState(BootSequence.CHECKING_LIBRARIES); checkPackagedLibrary(splashScreen, "enjarify", Constants.ENJARIFY_VERSION, BootSequence.CHECKING_ENJARIFY, BootSequence.CLEANING_ENJARIFY, BootSequence.MOVING_ENJARIFY); checkPackagedLibrary(splashScreen, "Krakatau", Constants.KRAKATAU_VERSION, BootSequence.CHECKING_KRAKATAU, BootSequence.CLEANING_KRAKATAU, BootSequence.MOVING_KRAKATAU); Helios.main(args, shell, splashScreen); while (!displayPumper.isDone()) { Thread.sleep(100); } } catch (Throwable t) { displayError(t); System.exit(1); } }
From source file:com.heliosdecompiler.helios.bootloader.Bootloader.java
public static void main(String[] args) { try {//w w w .ja va2 s .c o m if (!Constants.DATA_DIR.exists() && !Constants.DATA_DIR.mkdirs()) throw new RuntimeException("Could not create data directory"); if (!Constants.ADDONS_DIR.exists() && !Constants.ADDONS_DIR.mkdirs()) throw new RuntimeException("Could not create addons directory"); if (!Constants.SETTINGS_FILE.exists() && !Constants.SETTINGS_FILE.createNewFile()) throw new RuntimeException("Could not create settings file"); if (Constants.DATA_DIR.isFile()) throw new RuntimeException("Data directory is file"); if (Constants.ADDONS_DIR.isFile()) throw new RuntimeException("Addons directory is file"); if (Constants.SETTINGS_FILE.isDirectory()) throw new RuntimeException("Settings file is directory"); try { Class<?> clazz = Class.forName("org.eclipse.swt.widgets.Event"); Object location = clazz.getProtectionDomain() != null && clazz.getProtectionDomain().getCodeSource() != null ? clazz.getProtectionDomain().getCodeSource().getLocation() : ""; throw new RuntimeException("SWT should not be loaded. Instead, it was loaded from " + location); } catch (ClassNotFoundException ignored) { loadSWTLibrary(); } DisplayPumper displayPumper = new DisplayPumper(); if (System.getProperty("os.name").toLowerCase().contains("mac")) { System.out.println("Attemting to force main thread"); Executor executor; try { Class<?> dispatchClass = Class.forName("com.apple.concurrent.Dispatch"); Object dispatchInstance = dispatchClass.getMethod("getInstance").invoke(null); executor = (Executor) dispatchClass.getMethod("getNonBlockingMainQueueExecutor") .invoke(dispatchInstance); } catch (Throwable throwable) { throw new RuntimeException("Could not reflectively access Dispatch", throwable); } if (executor != null) { executor.execute(displayPumper); } else { throw new RuntimeException("Could not load executor"); } } else { Thread pumpThread = new Thread(displayPumper); pumpThread.setName("Display Pumper"); pumpThread.start(); } while (!displayPumper.isReady()) ; Display display = displayPumper.getDisplay(); Shell shell = displayPumper.getShell(); Splash splashScreen = new Splash(display); splashScreen.updateState(BootSequence.CHECKING_LIBRARIES); checkPackagedLibrary(splashScreen, "enjarify", Constants.ENJARIFY_VERSION, BootSequence.CHECKING_ENJARIFY, BootSequence.CLEANING_ENJARIFY, BootSequence.MOVING_ENJARIFY); checkPackagedLibrary(splashScreen, "Krakatau", Constants.KRAKATAU_VERSION, BootSequence.CHECKING_KRAKATAU, BootSequence.CLEANING_KRAKATAU, BootSequence.MOVING_KRAKATAU); try { if (!System.getProperty("os.name").toLowerCase().contains("linux")) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } catch (Exception exception) { //Not important. No point notifying the user } Helios.main(args, shell, splashScreen); synchronized (displayPumper.getSynchronizer()) { displayPumper.getSynchronizer().wait(); } System.exit(0); } catch (Throwable t) { displayError(t); System.exit(1); } }
From source file:org.jactr.core.module.AbstractModule.java
/** * create a future task and execute it on the exector * //w w w. j av a2 s.c o m * @param <T> * @param caller * @param executor * @return */ static public <T> Future<T> delayedFuture(Callable<T> caller, Executor executor) { FutureTask<T> future = new FutureTask<T>(caller); if (executor != null) executor.execute(future); else future.run(); return future; }
From source file:org.apache.helix.taskexecution.TaskExecutionDemo.java
private static void startWorkers(String zkAddr, String clusterName, TaskFactory taskFactory, TaskResultStore taskResultStore) { int numWorkers = NUM_WORKERS; Executor executor = Executors.newFixedThreadPool(numWorkers); for (int i = 0; i < numWorkers; i++) { Worker worker = new Worker(zkAddr, clusterName, "" + i, taskFactory, taskResultStore); executor.execute(worker); }/* w ww . jav a 2 s. c om*/ }
From source file:Main.java
public static long time(Executor executor, int concurrency, final Runnable action) throws InterruptedException { final CountDownLatch ready = new CountDownLatch(concurrency); final CountDownLatch start = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(concurrency); for (int i = 0; i < concurrency; i++) { executor.execute(new Runnable() { @Override// w w w . j ava2 s . c om public void run() { ready.countDown(); // Tell timer we're ready try { start.await(); // Wait till peers are ready action.run(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { done.countDown(); // Tell timer we're done } } }); } ready.await(); // Wait for all workers to be ready long startNanos = System.nanoTime(); start.countDown(); // And they're off! done.await(); // Wait for all workers to finish return System.nanoTime() - startNanos; }
From source file:org.sipfoundry.sipxconfig.admin.configdiag.ConfigurationDiagnosticContextImpl.java
/** * Similar to ExecutorService.invokeAll but this method is not going to block. You can check * the progress later by analysing returned futures. *///from ww w .j ava 2 s .c om static <T> List<Future<T>> scheduleAll(Executor executor, Collection<? extends Callable<T>> tasks) throws InterruptedException { List<Future<T>> futures = new ArrayList<Future<T>>(tasks.size()); for (Callable<T> t : tasks) { FutureTask<T> f = new FutureTask<T>(t); futures.add(f); executor.execute(f); } return futures; }
From source file:de.hshannover.f4.trust.iron.mapserver.contentauth.RemotePDP.java
private static void runServer(int port, LocalSunXacml pdp, int threads) { Executor clientExec = Executors.newFixedThreadPool(threads); ServerSocketFactory sockFac = ServerSocketFactory.getDefault(); try {//w ww . j ava 2s.c om ServerSocket sock = sockFac.createServerSocket(port); while (true) { Socket clientSock = sock.accept(); Runnable cmd = new HandleXacmlRequest(clientSock, pdp); System.out.println(nameDate() + "new client " + clientSock.getInetAddress()); clientExec.execute(cmd); } } catch (IOException e) { System.err.println(nameDate() + e.toString()); System.exit(1); } }
From source file:org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils.java
public static void publishTenantSubscribedEvent(int tenantId, String serviceName, Set<String> clusterIds) { Executor exec = new Executor() { @Override/*from w ww .j a va 2 s . c o m*/ public void execute(Runnable command) { command.run(); } }; exec.execute(new TenantSubscribedEventPublisher(tenantId, serviceName, clusterIds)); }
From source file:hudson.plugins.downstream_ext.DownstreamTrigger.java
public static void executeForProject(AbstractProject<?, ?> project, Runnable run) { Executor executor = executors.get(project); if (executor == null) { executor = Executors.newSingleThreadExecutor(); Executor old = executors.putIfAbsent(project, executor); if (old != null) { executor = old;/*from ww w .j a v a 2 s. c o m*/ } } executor.execute(run); }
From source file:org.apache.sshd.server.RunnableAbstractCommand.java
@Override public void start(final Environment env) throws IOException { final ExitCallback cbExit = getExitCallback(); Executor executor = getExecutor(); try {//from w w w . java 2 s. c o m executor.execute(new Runnable() { @Override public void run() { try { Integer exitCode = executeCommand(env); if (exitCode != null) { cbExit.onExit(exitCode.intValue()); } } catch (Throwable t) { getLogger().warn( "Failed (" + t.getClass().getSimpleName() + ") to execute: " + t.getMessage(), t); cbExit.onExit(EXIT_FAIL.intValue(), t.getClass().getName()); } } }); } catch (Throwable t) { logger.warn("Failed (" + t.getClass().getSimpleName() + ") to submit: " + t.getMessage(), t); cbExit.onExit(EXIT_FAIL.intValue(), t.getClass().getName()); } }