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:InterfaceTest.java

public static void main(String args[]) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("javascript");
    engine.eval("function run() {print('www.java2s.com');}");
    Invocable invokeEngine = (Invocable) engine;
    Runnable runner = invokeEngine.getInterface(Runnable.class);
    Thread t = new Thread(runner);
    t.start();
    t.join();//from   www.j a v a2s  .co  m
}

From source file:Main.java

public static void main(String[] args) throws InterruptedException {
    Thread t = new Thread(Main::run);
    t.start();
    Thread.sleep(5000);/*w  w w  .j  av  a  2 s .  c o  m*/
    t.interrupt();
}

From source file:Main.java

public static void main(String[] args) {
    Thread t = new Thread(Main::run);
    t.start();
    try {//from  ww  w  .  ja  v  a  2  s  .c  om
        Thread.currentThread().sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    t.interrupt();
}

From source file:ThreadDemo.java

public static void main(String[] args) {
    ThreadGroup tgrp = new ThreadGroup("Thread Group");
    Thread t = new Thread(tgrp, new ThreadDemo());
    t.start();
}

From source file:ThreadDemo.java

public static void main(String[] args) {

    Thread th = new Thread(new ThreadDemo());
    th.start();
}

From source file:ThreadDemo.java

public static void main(String[] args) throws Exception {
    Thread t = new Thread(new ThreadDemo());
    t.start();

}

From source file:Main.java

public static void main(String[] args) {
    Thread t1 = new Thread(Main::print);
    t1.start();
    try {//from   w w w  .  java 2s.  c o m
        t1.join();
        // "main" thread waits until t1 is terminated
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("Done.");
}

From source file:SleepInterrupt.java

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

    // Be sure that the new thread gets a chance to
    // run for a while.
    try {//from  w  w w  .j ava 2 s  .  c om
        Thread.sleep(2000);
    } catch (InterruptedException x) {
    }

    System.out.println("in main() - interrupting other thread");
    t.interrupt();
    System.out.println("in main() - leaving");
}

From source file:Main.java

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

    Thread t = new Thread(new ThreadDemo());
    t.start();
    // waits for this thread to die
    t.join();// w  ww  . j  a  v  a 2s  .c o m
    System.out.print(t.getName());
    // checks if this thread is alive
    System.out.println(", status = " + t.isAlive());
}

From source file:Main.java

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

    Thread t = new Thread(new ThreadDemo());
    t.start();

    t.join(2000, 500);//from   www .ja v  a 2  s  .  c  o  m
    //after waiting for 2000 milliseconds plus 500 nanoseconds ...
    System.out.print(t.getName());
    System.out.println(", status = " + t.isAlive());
}