List of usage examples for java.lang Runnable run
public abstract void run();
Runnable
is used to create a thread, starting the thread causes the object's run
method to be called in that separately executing thread. From source file:com.seovic.coherence.util.concurrent.ClusteredExecutorService.java
/** * Executes the given command at some time in the future. * * @param command the runnable task/*from ww w . j a va 2 s.c om*/ */ public void execute(Runnable command) { if (!(command instanceof ClusteredFutureTask)) { command = new ClusteredFutureTask<Object>(command, null); } command.run(); }
From source file:enumj.StreamComparator.java
public void test(BiConsumer<T, Optional<T>> elemAssert, Runnable lengthMismatchAsserter) { if (!built) { build();//from w ww. j a va2s .c o m } lhs.forEach(x -> elemAssert.accept(x, Optional.ofNullable(rhsHasNext() ? rhsNext() : null))); if (rhsHasNext()) { lengthMismatchAsserter.run(); } }
From source file:jetbrains.exodus.env.EnvironmentTestsBase.java
protected void runParallelRunnable(@NotNull final Runnable runnable) { processor.queue(new Job() { @Override/* www . j a v a2 s . c o m*/ protected void execute() throws Throwable { runnable.run(); } }); }
From source file:com.moss.greenshell.wizard.ProcessPanel.java
private void runOnEventDispatchThread(Runnable action) { try {/*from w w w .j a va 2 s. co m*/ if (SwingUtilities.isEventDispatchThread()) { action.run(); } else { SwingUtilities.invokeLater(action); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:gda.scan.MultiScanRunner.java
@Override public void runScan() throws InterruptedException, Exception { try {/*www . j a v a 2 s . c om*/ setStatus(ScanStatus.RUNNING); if (LocalProperties.check(ScanBase.GDA_SCANBASE_PRINT_TIMESTAMP_TO_TERMINAL)) { java.util.Date date = new java.util.Date(); getTerminalPrinter() .print("=== Scan started at " + new Timestamp(date.getTime()).toString() + " ==="); } for (MultiScanItem item : scans) { TotalNumberOfPoints += item.scan.getTotalNumberOfPoints(); } MultiScanItem multiScanItem = scans.get(0); first = multiScanItem.scan; first.prepareScanForCollection(); int pointCount = -1; for (MultiScanItem item : scans) { ScanBase scan = item.scan; lastscan = scan; for (Detector det : scan.getDetectors()) { if (det instanceof HardwareTriggeredDetector) { ((HardwareTriggeredDetector) det).setNumberImagesToCollect(scan.getTotalNumberOfPoints()); } } scan.setIsChild(true); scan.setParent(this); scan.setScanDataPointPipeline(first.getScanDataPointPipeline()); scan.setScanNumber(first.getScanNumber()); // run the scan scan.currentPointCount = pointCount; scan.name = first.name; Runnable prescan = item.prescan; if (prescan != null) { prescan.run(); } scan.callScannablesAtScanStart(); scan.run(); pointCount = scan.currentPointCount; } for (MultiScanItem item : scans) { ScanBase scan = item.scan; scan.callScannablesAtScanEnd(); scan.callDetectorsEndCollection(); } if (lastscan != null) { lastscan.shutdownScandataPipeline(true); } } catch (Exception e) { logger.error("Error running multiScan", e); if (lastscan != null) { lastscan.shutdownScandataPipeline(false); } throw e; } finally { switch (getStatus()) { case RUNNING: setStatus(ScanStatus.COMPLETED_OKAY); break; case TIDYING_UP_AFTER_FAILURE: setStatus(ScanStatus.COMPLETED_AFTER_FAILURE); break; case TIDYING_UP_AFTER_STOP: setStatus(ScanStatus.COMPLETED_AFTER_STOP); break; case FINISHING_EARLY: setStatus(ScanStatus.COMPLETED_EARLY); break; default: throw new AssertionError("Unexpected status at the end of scan:" + getStatus().toString()); } if (lastscan != null) { lastscan.signalScanComplete(); } } }
From source file:org.openvpms.component.business.service.archetype.rule.ArchetypeRuleService.java
/** * Executes an operation in a transaction, with before and after rules. * <ol>//from w w w . j a va 2 s . c o m * <li>begin transaction * <li>execute <em>before</em> rules for each object * <li>execute {@code operation} * <li>execute <em>after</em> rules for each object * <li>commit on success/rollback on failure * </ol> * * @param name the name of the operation * @param objects the object that will be supplied to before and after rules * @param op the operation to execute */ private void execute(final String name, final Collection<? extends IMObject> objects, final Runnable op) { template.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { for (IMObject object : objects) { executeRules(name, object, true); } op.run(); for (IMObject object : objects) { executeRules(name, object, false); } return null; } }); }
From source file:org.brekka.pegasus.core.services.impl.PegasusPrincipalServiceImpl.java
@Override public void doWithPrincipal(final PegasusPrincipal principal, final Runnable runnable) { PegasusPrincipalImpl previous = threadLocalPrincipals.get(); try {// www. j a v a 2 s . c om threadLocalPrincipals.set((PegasusPrincipalImpl) principal); runnable.run(); } finally { threadLocalPrincipals.set(previous); } }
From source file:com.hypersocket.upgrade.UpgradeServiceImpl.java
private void executeScript(Map<String, Object> beans, URL script) throws ScriptException, IOException { if (log.isInfoEnabled()) { log.info("Executing script " + script); }// w w w .j a v a2 s .c o m if (script.getPath().endsWith(".js")) { ScriptContext context = new SimpleScriptContext(); ScriptEngine engine = buildEngine(beans, script, context); InputStream openStream = script.openStream(); if (openStream == null) { throw new FileNotFoundException("Could not locate resource " + script); } Reader in = new InputStreamReader(openStream); try { engine.eval(in, context); } finally { in.close(); } } else if (script.getPath().endsWith(".class")) { String path = script.getPath(); int idx = path.indexOf("upgrade/"); path = path.substring(idx); idx = path.lastIndexOf("."); path = path.substring(0, idx).replace("/", "."); try { @SuppressWarnings("unchecked") Class<? extends Runnable> clazz = (Class<? extends Runnable>) getClass().getClassLoader() .loadClass(path); Runnable r = clazz.newInstance(); springContext.getAutowireCapableBeanFactory().autowireBean(r); r.run(); } catch (Exception e) { throw new RuntimeException(e); } } else { BufferedReader r = new BufferedReader(new InputStreamReader(script.openStream())); try { String statement = ""; String line; boolean ignoreErrors = false; while ((line = r.readLine()) != null) { line = line.trim(); if (line.startsWith("EXIT IF FRESH")) { if (isFreshInstall()) { break; } continue; } if (!line.startsWith("/*") && !line.startsWith("//")) { if (line.endsWith(";")) { line = line.substring(0, line.length() - 1); statement += line; sessionFactory.getCurrentSession().createSQLQuery(statement).executeUpdate(); statement = ""; } else { statement += line + "\n"; } } } if (StringUtils.isNotBlank(statement)) { try { sessionFactory.getCurrentSession().createSQLQuery(statement).executeUpdate(); } catch (Throwable e) { if (!ignoreErrors) { throw e; } } } } finally { r.close(); } } }
From source file:LinkList.java
public void executeOnValue(E desiredValue, Runnable task) throws InterruptedException { lock.lock();//from www .j a v a2s . co m try { // Checks the value against the desired value while (!value.equals(desiredValue)) { // This will wait until the value changes valueChanged.await(); } // When we get here, the value is correct -- Run the task task.run(); } finally { lock.unlock(); } }
From source file:com.github.mrstampy.gameboot.usersession.UserSessionAssistTest.java
private void testLogout(Runnable r) throws Exception { User user = assist.expectedUser(USER_NAME); UserSession session = createSession(user); assertNull(session.getEnded());/* ww w .j a va 2 s. c o m*/ assertTrue(assist.hasSession(sessionId)); r.run(); assertFalse(assist.hasSession(sessionId)); assertNotNull(session.getEnded()); }