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:net.sf.janos.Janos.java

/**
 * @param args/*  w ww  . ja  v a  2s . c o m*/
 * @throws Exception 
 */
public static void main(String[] args) {
    if (args.length > 1) {
        System.out.println("Usage: Janos [port]");
        System.exit(1);
    }

    if (args.length == 1) {
        System.setProperty("net.sbbi.upnp.Discovery.bindPort", args[0]);
    }

    /*
     * [DW] For some reason unknown to me, given: 
     * 1) arch is intel
     * 2) os is Mac OS X 
     * 3) running in eclipse
     * 4) using SWT
     * no exceptions are displayed in the eclipse console in the main thread. 
     * To work around this, we just do everything in a new thread :-)
     */
    if (Boolean.getBoolean("net.sf.janos.forkNewThread")) {
        try {
            Thread mainThread = new Thread(new Janos(), "Janos-SWT");
            mainThread.start();
            mainThread.join();
        } catch (Throwable t) {
            LogFactory.getLog(Janos.class).fatal("Could not start thread: ", t);
            System.exit(1);
        }
    } else {
        new Janos().run();
    }
}

From source file:Main.java

public static void main(String[] args) {
    Thread t = new Thread(new Main());
    t.setUncaughtExceptionHandler(new OverrideExceptionHandler());
    System.out.println(t.getUncaughtExceptionHandler());
    t.start();
}

From source file:MyThread.java

public static void main(String[] args) throws Exception {

    Thread thread = new MyThread();
    System.out.println("thread = " + thread.currentThread());
    thread.setDaemon(true);/*from  w  w w .ja v  a  2s .co  m*/

    // this will call run() method
    thread.start();
}

From source file:Test.java

public static void main(String[] args) {
    Thread producerThread = new Thread(new ItemProducer());
    Thread consumerThread = new Thread(new ItemConsumer());
    producerThread.start();
    consumerThread.start();//  www  . j  a va  2 s .co m
}

From source file:TryThread.java

public static void main(String[] args) {
    Thread first = new TryThread("A ", "a ", 200L);
    Thread second = new TryThread("B ", "b ", 300L);
    Thread third = new TryThread("C ", "c ", 500L);
    first.start();
    second.start();//from   ww  w .j  a va2  s .  c o m
    third.start();
    try {
        first.join(2000); // Wait up to 2 second for thread1 to die
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    Thread thread1 = new Thread(new PipeOutput("Producer"));
    Thread thread2 = new Thread(new PipeInput("Consumer"));
    thread1.start();
    thread2.start();//from w ww.ja va2  s. co m
    boolean thread1IsAlive = true;
    boolean thread2IsAlive = true;
    do {
        if (thread1IsAlive && !thread1.isAlive()) {
            thread1IsAlive = false;
        }
        if (thread2IsAlive && !thread2.isAlive()) {
            thread2IsAlive = false;
        }
    } while (thread1IsAlive || thread2IsAlive);
}

From source file:TryThread.java

public static void main(String[] args) {
    Thread first = new TryThread("A ", "a ", 200L);
    Thread second = new TryThread("B ", "b ", 300L);
    Thread third = new TryThread("C ", "c ", 500L);
    first.start();
    second.start();//ww w. ja  va2  s .co  m
    third.start();
    try {
        Thread.sleep(3000);
        first.interrupt();
        second.interrupt();
        third.interrupt();
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:Test.java

public static void main(String[] args) {
    final Lock firstLock = new ReentrantLock();
    final Lock secondLock = new ReentrantLock();
    firstLock.lock();/*from   w  ww .j a  va  2  s .c  o m*/
    Thread secondThread = new Thread(new Runnable() {
        public void run() {
            secondLock.lock();
            firstLock.lock();
        }
    });
    secondThread.start();
    try {
        Thread.sleep(250);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    secondLock.lock();

    secondLock.unlock();
    firstLock.unlock();
}

From source file:TestOverrideThread.java

public static void main(String[] args) {
    Thread t = new Thread(new TestOverrideThread());
    t.setUncaughtExceptionHandler(new OverrideExceptionHandler());
    System.out.println(t.getUncaughtExceptionHandler());
    t.start();
}

From source file:UnsynchBankTest.java

public static void main(String[] args) {
    Bank b = new Bank(NACCOUNTS, INITIAL_BALANCE);
    int i;//from   w  ww  .ja  v a2  s . c om
    for (i = 0; i < NACCOUNTS; i++) {
        TransferRunnable r = new TransferRunnable(b, i, INITIAL_BALANCE);
        Thread t = new Thread(r);
        t.start();
    }
}