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:org.grails.datastore.mapping.core.AbstractSession.java

private void executePendings(Collection<Runnable> pendings) {
    try {/*  w  w  w .  ja  va2s  . c om*/
        for (Runnable pending : pendings) {
            pending.run();
        }
    } catch (RuntimeException e) {
        exceptionOccurred = true;
        throw e;
    }
    pendings.clear();
}

From source file:com.twinsoft.convertigo.eclipse.ConvertigoPlugin.java

static public void runAtStartup(Runnable runnable) {
    if (Engine.isStarted) {
        runnable.run();
    } else {/*  w  w  w  .  jav a 2 s . c  om*/
        plugin.runAtStartup.add(runnable);
    }

}

From source file:de.wikilab.android.friendica01.Notification.java

public void resolveTarget(Context ctx, final Runnable done) {
    final TwAjax resT = new TwAjax(ctx, true, true);
    resT.fetchUrlHeader("GET", this.href, "Location", new Runnable() {
        @Override/* w  ww  .ja  v a 2s . c o  m*/
        public void run() {

            targetUrl = resT.fetchHeaderResult[0].getValue();

            if (targetUrl.endsWith("/message/")) {
                targetComponent = "msg:all";
            }

            Matcher m = Max.regeximatch(".*/display/.*/([0-9]+)/?", targetUrl);
            if (m.matches()) {
                targetComponent = "conversation:";
                targetData = m.group(1);
            }

            done.run();
        }
    });
}

From source file:com.zavakid.mushroom.impl.TestSinkQueue.java

/**
 * Test blocking when queue is empty/*w  w w  .  j av  a 2 s  .  co m*/
 * 
 * @throws Exception
 */
@Test
public void testEmptyBlocking() throws Exception {
    final SinkQueue<Integer> q = new SinkQueue<Integer>(2);
    final Runnable trigger = mock(Runnable.class);
    // try consuming emtpy equeue and blocking
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                assertEquals("element", 1, (int) q.dequeue());
                q.consume(new Consumer<Integer>() {

                    public void consume(Integer e) {
                        assertEquals("element", 2, (int) e);
                        trigger.run();
                    }
                });
            } catch (InterruptedException e) {
                LOG.warn("Interrupted", e);
            }
        }
    };
    t.start();
    Thread.yield(); // Let the other block
    q.enqueue(1);
    q.enqueue(2);
    t.join();
    verify(trigger).run();
}

From source file:de.hska.ld.core.service.impl.UserServiceImpl.java

@Override
public void runAs(User user, Runnable runnable) {
    Authentication authenticationBefore = SecurityContextHolder.getContext().getAuthentication();
    SecurityContextHolder.getContext().setAuthentication(
            new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities()));
    try {//from w w  w.j  a v  a 2  s.  co  m
        runnable.run();
    } finally {
        SecurityContextHolder.getContext().setAuthentication(authenticationBefore);
    }
}

From source file:co.beem.project.beem.FbTextService.java

public static Thread savingMessageOnBackgroundThread(final Runnable runnable) {
    final Thread t = new Thread() {
        @Override/*  w w  w.  j a va  2 s.  c o m*/
        public void run() {
            try {
                runnable.run();
            } finally {

            }
        }
    };
    t.start();
    return t;
}

From source file:org.lol.reddit.activities.ImageViewActivity.java

private void revertToWeb() {

    final Runnable r = new Runnable() {
        public void run() {
            if (!mHaveReverted) {
                mHaveReverted = true;// www .ja  va  2  s .c o m
                LinkHandler.onLinkClicked(ImageViewActivity.this, mUrl.toString(), true);
                finish();
            }
        }
    };

    if (General.isThisUIThread()) {
        r.run();
    } else {
        General.UI_THREAD_HANDLER.post(r);
    }
}

From source file:org.martus.client.swingui.PureFxMainWindow.java

public void runInUiThreadAndWait(final Runnable toRun) throws InterruptedException, InvocationTargetException {
    if (Platform.isFxApplicationThread()) {
        toRun.run();
        return;//from w  w  w .ja  v a  2 s  . c o m
    }

    final CountDownLatch doneLatch = new CountDownLatch(1);
    Platform.runLater(() -> {
        try {
            toRun.run();
        } finally {
            doneLatch.countDown();
        }
    });

    doneLatch.await();
}

From source file:WorkThreadPool.java

/**
 * Adds a work request to the queue.//from ww w  . j  a  v a2 s.  c  o  m
 * 
 * @param run
 *          The runnable
 * @param inAWT
 *          If true, will be executed in AWT thread. Otherwise, will be
 *          executed in work thread
 */
public void addWorkRequest(Runnable run, boolean inAWT) {
    if (threads == null) {
        run.run();
        return;
    }

    synchronized (lock) {
        // {{{ if there are no requests, execute AWT requests immediately
        if (started && inAWT && requestCount == 0 && awtRequestCount == 0) {
            // Log.log(Log.DEBUG,this,"AWT immediate: " + run);

            if (SwingUtilities.isEventDispatchThread())
                run.run();
            else
                SwingUtilities.invokeLater(run);

            return;
        } // }}}

        Request request = new Request(run);

        // {{{ Add to AWT queue...
        if (inAWT) {
            if (firstAWTRequest == null && lastAWTRequest == null)
                firstAWTRequest = lastAWTRequest = request;
            else {
                lastAWTRequest.next = request;
                lastAWTRequest = request;
            }

            awtRequestCount++;

            // if no requests are running, requestDone()
            // will not be called, so we must queue the
            // AWT runner ourselves.
            if (started && requestCount == 0)
                queueAWTRunner();
        } // }}}
          // {{{ Add to work thread queue...
        else {
            if (firstRequest == null && lastRequest == null)
                firstRequest = lastRequest = request;
            else {
                lastRequest.next = request;
                lastRequest = request;
            }

            requestCount++;
        } // }}}

        lock.notifyAll();
    }
}

From source file:com.eucalyptus.tests.awssdk.S3ListMpuTests.java

@AfterMethod
public void cleanup() throws Exception {
    Collections.reverse(cleanupTasks);
    for (final Runnable cleanupTask : cleanupTasks) {
        try {/*w ww  .  j  a  v a  2  s .com*/
            cleanupTask.run();
        } catch (Exception e) {
            print("Unable to run clean up task: " + e);
        }
    }
}