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:org.tomitribe.tribestream.registryng.test.Registry.java
public void withRetries(final Runnable task, final String... description) { withRetries(() -> {//w w w . j ava2 s.c o m task.run(); return null; }); }
From source file:com.reprezen.kaizen.oasparser.val.ValidationResults.java
public void withCrumb(String crumb, Runnable code) { List<String> priorCrumbs = crumbs; try {//from www. java 2 s. c om crumbs = appendCrumb(crumb, priorCrumbs); code.run(); } finally { crumbs = priorCrumbs; } }
From source file:pl.exsio.frameset.vaadin.bootstrap.spring.scope.UIScope.java
private void removeBeans(UI ui) { Set<String> keys = beans.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String key = iter.next(); String prefix = getConversationId(ui); if (key.startsWith(prefix)) { iter.remove();/*from w w w . java2 s . c o m*/ if (log.isDebugEnabled()) { log.debug("Removed bean [" + key + "]"); } Runnable callback = callbacks.remove(key); if (callback != null) { callback.run(); } } } }
From source file:com.facebook.LinkBench.LinkBenchDriverInj.java
/** * Start all runnables at the same time. Then block till all * tasks are completed. Returns the elapsed time (in millisec) * since the start of the first task to the completion of all tasks. *//*from www . j a v a2 s. co m*/ static long concurrentExec(final List<? extends Runnable> tasks, boolean runReq, Random rng) throws Throwable { final CountDownLatch startSignal = new CountDownLatch(tasks.size()); final CountDownLatch doneSignal = new CountDownLatch(tasks.size()); final AtomicLong startTime = new AtomicLong(0); for (final Runnable task : tasks) { new Thread(new Runnable() { @Override public void run() { /* * Run a task. If an uncaught exception occurs, bail * out of the benchmark immediately, since any results * of the benchmark will no longer be valid anyway */ try { startSignal.countDown(); startSignal.await(); long now = System.currentTimeMillis(); startTime.compareAndSet(0, now); task.run(); } catch (Throwable e) { Logger threadLog = Logger.getLogger(ConfigUtil.LINKBENCH_LOGGER); threadLog.error("Unrecoverable exception in worker thread:", e); Runtime.getRuntime().halt(1); } doneSignal.countDown(); } }).start(); } if (runReq) { /* Do logic with injection rate. All tasks above should be waiting on tasks */ long reqTime_ns = System.nanoTime(); double requestrate_ns = ((double) requestrate) / 1e9; long numRequests = ConfigUtil.getLong(props, Config.NUM_REQUESTS); System.out.println("Processing Requests:" + genQueue); try { long runStartTime = System.currentTimeMillis(); long curTime = runStartTime; for (int i = 0; i < numRequests; i++) { reqTime_ns = Timer.waitExpInterval(rng, reqTime_ns, requestrate_ns); // System.out.println("Request time: "+System.currentTimeMillis()); genQueue.put(System.nanoTime()); curTime = System.currentTimeMillis(); if (curTime > runStartTime + maxTime * 1000) { System.out.println("Time limit elapsed"); break; } } // Send stop signal to all requesters for (int i = 0; i < nrequesters; i++) { genQueue.put((long) 0); } } catch (Exception e) { e.printStackTrace(); } } doneSignal.await(); // wait for all threads to finish long endTime = System.currentTimeMillis(); return endTime - startTime.get(); }
From source file:com.ponysdk.ui.server.basic.PWindow.java
private void executePostedCommand() { for (final Runnable r : postedCommands) { try {//from w w w .j a va 2 s .com r.run(); } catch (final Throwable e) { log.error("Failed to execute command: " + r, e); } } postedCommands.clear(); }
From source file:com.github.mrstampy.gameboot.usersession.UserSessionLookupTest.java
private void gameBootExcpected(Runnable r, String failMsg) { try {// www. j av a2 s .co m r.run(); fail(failMsg); } catch (GameBootRuntimeException expected) { } }
From source file:com.heisenberg.test.other.JobServiceTest.java
public void initialize() { initializeProcessEngine();/* w ww . j av a 2s. c o m*/ this.jobService = processEngine.getServiceRegistry().getService(JobService.class); JobServiceImpl jobServiceImpl = (JobServiceImpl) jobService; // let's skip starting any threads jobServiceImpl.isRunning = true; // and execute the jobs in the test thread.. jobServiceImpl.executor = new ExecutorService() { public void startup() { } public void shutdown() { } public int getQueueDepth() { return 0; } public void execute(Runnable command) { command.run(); } }; }
From source file:de.micromata.mgc.javafx.ControllerService.java
public void runInToolkitThread(final Runnable runnable) { if (Platform.isFxApplicationThread() == true) { runnable.run(); return;/* www . j a v a2 s . c o m*/ } Platform.runLater(runnable); }
From source file:com.cedarsoft.serialization.test.performance.StaxMateDelegatePerformance.java
private void runBenchmark(@Nonnull Runnable runnable, final int count) { //Warmup//ww w . java 2s.c o m runnable.run(); runnable.run(); runnable.run(); List<Long> times = new ArrayList<Long>(); for (int i = 0; i < count; i++) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); runnable.run(); stopWatch.stop(); times.add(stopWatch.getTime()); } System.out.println("-----------------------"); for (Long time : times) { System.out.println("--> " + time); } System.out.println("-----------------------"); }
From source file:ThreadPoolMain.java
private void runIt(Runnable r) { try {/* www .j av a 2 s . c o m*/ r.run(); } catch (Exception runex) { System.err.println("Uncaught exception fell through from run()"); runex.printStackTrace(); } finally { Thread.interrupted(); } }