Example usage for java.lang Runnable run

List of usage examples for java.lang Runnable run

Introduction

In this page you can find the example usage for java.lang Runnable run.

Prototype

public abstract void run();

Source Link

Document

When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Usage

From source file:edu.umn.msi.tropix.common.concurrent.impl.TimerImpl.java

public synchronized void schedule(final Runnable runnable, final long delay) {
    timer.schedule(new TimerTask() {
        public void run() {
            try {
                runnable.run();
            } catch (final RuntimeException e) {
                ExceptionUtils.logQuietly(LOG, e);
            }//from  w  w  w.j a va 2  s  .c o m
        }
    }, delay);
}

From source file:com.facebook.LinkBench.LinkBenchDriver.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.
 *///  w  ww  .ja v a 2  s. c o m
static long concurrentExec(final List<? extends Runnable> tasks) 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();
    }
    doneSignal.await(); // wait for all threads to finish
    long endTime = System.currentTimeMillis();
    return endTime - startTime.get();
}

From source file:com.acuityph.commons.util.Benchmark.java

/**
 * Run and benchmark a {@link Runnable} task.
 *
 * @param runnable//  www.  ja v a 2s. co  m
 *        the {@link Runnable} to run
 */
public final void run(final Runnable runnable) {
    start();
    try {
        runnable.run();
    } finally {
        stop();
    }
}

From source file:org.hawkular.rest.ResponseUtil.java

private static <T> InputStream pageToStream(Page<T> page, ObjectMapper mapper, Runnable callback)
        throws IOException {
    final PipedOutputStream outs = new PipedOutputStream();
    final PipedInputStream ins = new PipedInputStream() {
        @Override// w  w  w .j a  v  a  2s  . c om
        public void close() throws IOException {
            outs.close();
            super.close();
        }
    };
    outs.connect(ins);
    mapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

    PageToStreamThreadPool.getInstance().submit(() -> {
        try (Page<T> closeablePage = page;
                PipedOutputStream out = outs;
                SequenceWriter sequenceWriter = mapper.writer().writeValuesAsArray(out)) {
            for (T element : closeablePage) {
                sequenceWriter.write(element);
                sequenceWriter.flush();
            }
        } catch (IOException e) {
            throw new IllegalStateException("Unable to convert page to input stream.", e);
        } finally {
            callback.run();
        }
    });
    return ins;
}

From source file:org.vaadin.spring.internal.UIStore.java

@Override
public void detach(ClientConnector.DetachEvent event) {
    logger.debug("Received DetachEvent from [{}]", event.getSource());
    final UIID uiIdentifier = new UIID((UI) event.getSource());
    final Map<String, Runnable> destructionSpace = destructionCallbackMap.remove(uiIdentifier);
    if (destructionSpace != null) {
        for (Runnable runnable : destructionSpace.values()) {
            runnable.run();
        }/*from w ww . ja v  a2  s  . com*/
    }
    objectMap.remove(uiIdentifier);
}

From source file:com.acuityph.commons.util.Benchmark.java

/**
 * Run and benchmark a named {@link Runnable} task.
 *
 * @param taskName//from ww  w.j  ava  2 s.  c  o m
 *        the task name
 * @param runnable
 *        the {@link Runnable} to run
 */
public final void run(final String taskName, final Runnable runnable) {
    start(taskName);
    try {
        runnable.run();
    } finally {
        stop();
    }
}

From source file:com.qubit.solution.fenixedu.integration.cgd.services.form43.CgdForm43Sender.java

private static void executeIfAllowed(org.fenixedu.academic.domain.Person person, String dataShareQuestionCode,
        Runnable executeIfAuthorized) {

    //  Jos Lima stated in 30 July 2018 that the basic info fields (the ones that are needed to create the university 
    //  card) must always be provided. So the BASIC_INFO is not actually an authorization but rather an information to 
    //  he user that those fields will be sent (since the card is mandatory). 
    ////from w  w  w. j av  a  2 s .  co m
    //  Due to that fact instead of checking for the authorization, if it's something under BASIC_INFO authorization
    //  we just execute it, this way the rest of the code still maintains it's executeIfAllowed policy.
    //
    if (dataShareQuestionCode.equals(CgdAuthorizationCodes.BASIC_INFO)) {
        executeIfAuthorized.run();
    } else {
        DataShareAuthorization authorization = DataShareAuthorization.findLatest(person,
                DataShareAuthorizationType.findUnique(dataShareQuestionCode));
        if (authorization != null && authorization.getAllow()) {
            executeIfAuthorized.run();
        }
    }
}

From source file:org.javersion.store.jdbc.SpringTransactions.java

@Override
public void afterCommit(final Runnable callback) {
    registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override/* w w w. j av  a  2 s  .co  m*/
        public void afterCommit() {
            callback.run();
        }
    });
}

From source file:at.molindo.esi4j.util.ListenableAsyncResult.java

private void executeListener(final Runnable listener) {
    if (_threadPool != null) {
        _threadPool.generic().execute(listener);
    } else {/*w w w  .  j  av a  2 s.c om*/
        listener.run();
    }
}

From source file:com.moss.appprocs.swing.ProgressDialog.java

private void runOnEventDispatchThread(Runnable r) {
    if (SwingUtilities.isEventDispatchThread()) {
        r.run();
    } else {/*ww  w.j av  a  2 s. c  om*/
        SwingUtilities.invokeLater(r);
    }
}