Example usage for java.lang Thread start

List of usage examples for java.lang Thread start

Introduction

In this page you can find the example usage for java.lang Thread start.

Prototype

public synchronized void start() 

Source Link

Document

Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

Usage

From source file:Main.java

/**
 * Make an asynchronous call in a separate thread, with a callback that's run on the current
 * Android UI thread./*from  w  ww.  ja  v  a2  s. c o  m*/
 * @param androidUIHandler  the Handler from the current Android context
 * @param call a {@link Runnable} to run in the thread.
 * @param callback a {@link Runnable} to run in the Android UI thread when the call above returns
 */
public static void runAsynchronously(final Handler androidUIHandler, final Runnable call,
        final Runnable callback) {
    Runnable runnable = new Runnable() {
        public void run() {
            call.run();
            if (callback != null) {
                androidUIHandler.post(new Runnable() {
                    public void run() {
                        callback.run();
                    }
                });
            }
        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
}

From source file:Main.java

public static Thread spawn(Runnable runnable) {

    final Thread thread = new Thread(runnable);
    thread.setDaemon(false);//from  w w w  . jav a 2 s  .  co m
    thread.start();

    return thread;
}

From source file:Main.java

public static void start(Runnable executer, String threadName, boolean demon) {
    Thread thread = new Thread(executer, threadName);
    thread.setDaemon(demon);//from  w  w w  .  j  a v  a  2s.  co  m
    thread.start();
}

From source file:Main.java

public static void runLater(final Runnable r) {
    Thread t = new Thread(r, "ThreadUtils.runLater-Thread");
    t.setDaemon(true);//from   w ww .  j ava  2 s. c om
    t.start();
}

From source file:Main.java

public static void runAsDaemon(Runnable runnable) {
    Thread thread = new Thread(runnable);
    thread.setDaemon(true);/*from   www .  j  ava2s.c o  m*/
    thread.start();
}

From source file:Main.java

public static Thread runAsync(Runnable runnable, String threadName, boolean daemon) {
    Thread thread = new Thread(runnable, threadName);
    thread.setDaemon(daemon);/*from  www . ja v a2  s  .  c om*/
    thread.start();
    return thread;
}

From source file:com.mindcognition.mindraider.utils.FileLoader.java

public static void loadFile(String url, JTextArea doc) {
    File f = new File(url);
    if (f.exists()) {
        Thread loader = new FileLoader(f, doc);
        loader.start();
    }//from   w ww .  j  ava  2 s  . c  om
}

From source file:Main.java

public static void runInThread(final Runnable runnable) throws Throwable {
    final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
    Runnable exceptionGuard = new Runnable() {
        public void run() {
            try {
                runnable.run();/*from ww  w .j  a va2s.  c  o  m*/
            } catch (Throwable throwable) {
                exception.set(throwable);
            }
        }
    };
    Thread thread = new Thread(exceptionGuard);
    thread.setDaemon(true);
    thread.start();
    thread.join();
    if (exception.get() != null) {
        throw exception.get();
    }
}

From source file:CreateTest.java

static void doTestCreate() {
    done = false;/*from www.  j av  a  2  s  .c  o m*/
    nCalls = new AtomicInteger(0);
    for (int i = 0; i < target; i++) {
        Thread t = new CreateTest();
        t.start();
    }
    synchronized (lock) {
        while (!done)
            try {
                lock.wait();
            } catch (Exception e) {
            }
    }
}

From source file:Main.java

public static void run(final String name, final Runnable r) {
    Thread t = new Thread(name) {
        public void run() {
            r.run();//from   w  ww . j ava  2s.c  om
        }
    };
    t.start();
}