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

public static void main(String[] args) {
    try {//  w w  w . ja  v a2s .  c  o m
        Thread t = new Main();
        t.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

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

    Thread t = new Thread(new ThreadDemo());
    t.start();
    // waits at most 2000 milliseconds for this thread to die.
    t.join(2000);/*from w  ww  . ja va 2s.  c  om*/

    // after waiting for 2000 milliseconds...
    System.out.print(t.getName());

    System.out.println(", status = " + t.isAlive());
}

From source file:Main.java

public static void main(String args[]) {
    final Map<String, String> map = new WeakHashMap<String, String>();
    map.put(new String("A"), "B");
    Runnable runner = new Runnable() {
        public void run() {
            while (map.containsKey("A")) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ignored) {
                }//from  w  w w  .  j  av  a 2  s .  c  om
                System.gc();
            }
        }
    };

    Thread t = new Thread(runner);
    t.start();
    try {
        t.join();
    } catch (InterruptedException ignored) {
    }
}

From source file:PiInterrupt.java

public static void main(String[] args) {
    PiInterrupt pi = new PiInterrupt();
    Thread t = new Thread(pi);
    t.start();

    try {/*from www. ja va 2 s. c  om*/
        Thread.sleep(10000);
        t.interrupt();
    } catch (InterruptedException x) {
    }
}

From source file:AlternateStop.java

public static void main(String[] args) {
    AlternateStop as = new AlternateStop();
    Thread t = new Thread(as);
    t.start();

    try {/*  w ww. j a  va  2  s.co m*/
        Thread.sleep(2000);
    } catch (InterruptedException x) {
    }
    as.stopRequest();
}

From source file:Weak.java

public static void main(String args[]) {
    final Map map = new WeakHashMap();
    map.put(new String("Java2s"), "www.java2s.com");
    Runnable runner = new Runnable() {
        public void run() {
            while (map.containsKey("Java2s")) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ignored) {
                }/*  w w  w  .  java  2  s  .  c o  m*/
                System.out.println("Waiting");
                System.gc();
            }
        }
    };
    Thread t = new Thread(runner);
    t.start();
    System.out.println("Main waiting");
    try {
        t.join();
    } catch (InterruptedException ignored) {
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Thread thread = new MyThread();
    thread.start();

    if (thread.isAlive()) {
        System.out.println("Thread has not finished");
    } else {//from ww  w.j ava 2s  . c  om
        System.out.println("Finished");
    }
    long delayMillis = 5000; // 5 seconds
    thread.join(delayMillis);

    if (thread.isAlive()) {
        System.out.println("thread has not finished");
    } else {
        System.out.println("Finished");
    }
    thread.join();
}

From source file:MainClass.java

public static void main(String[] args) {
    ThreadGroup tg = new OverrideThreadGroup();

    Thread t = new Thread(tg, new MainClass());
    t.start();
}

From source file:MainClass.java

public static void main(String[] args) {
    try {//from ww  w  .  j  a va  2 s  . c  o  m
        Thread t = new MainClass();
        t.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:MyThread.java

public static void main(String[] argv) throws Exception {
    Thread thread = new MyThread();
    thread.setDaemon(true);//from w  ww . jav  a 2  s. com
    thread.start();
}