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

public static void main(String arg[]) throws Exception {
    System.out.println("Main");
    Thread t1 = new Thread() {
        public void run() {
            Main2.main(new String[] {});
        }//from w ww  . j a  va  2 s. c o m
    };
    t1.start();
    t1.join();
    System.out.println("Main again");
}

From source file:ThreadDemo.java

public static void main(String args[]) {
    Thread t = new Thread(new ThreadDemo(), "java2s.com thread");
    t.setPriority(1);//  w w  w. jav  a  2 s  .c o m

    System.out.println("thread  = " + t);

    t.start();
}

From source file:MyThread.java

public static void main(String args[]) throws Exception {
    Thread thrd = new Thread(new MyThread(), "MyThread #1");
    Thread thrd2 = new Thread(new MyThread(), "MyThread #2");
    thrd.start();
    Thread.sleep(100);/*from  w  ww.j a v  a  2 s .com*/
    thrd.interrupt();
    thrd2.start();
    Thread.sleep(400);
    thrd2.interrupt();
}

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(false);//from   w  ww.  j a  va 2s. c o m

    thread.start();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    String hostname = "localhost";
    InetAddress ia = InetAddress.getByName(hostname);
    SenderThread sender = new SenderThread(ia, 1919);
    sender.start();/*w ww .j a va  2  s  . c om*/
    Thread receiver = new ReceiverThread(sender.getSocket());
    receiver.start();
}

From source file:Main.java

public static void main(String[] args) {
    Thread t = new Thread(() -> {
        while (true) {
            updateBalance();// w ww  .j ava  2s .  c  o  m
        }
    });
    t.start();
    t = new Thread(() -> {
        while (true) {
            monitorBalance();
        }
    });
    t.start();
}

From source file:PrepareProduction.java

public static void main(String[] args) throws Exception {
    BlockingQueue<String> q = new LinkedBlockingQueue<String>();
    Thread p1 = new Thread(new PrepareProduction(q));
    Thread c1 = new Thread(new DoProduction(q));
    p1.start();
    c1.start();//from   ww  w .j ava2  s . c  om
    p1.join();
    c1.join();
}

From source file:MyThread.java

public static void main(String args[]) throws Exception {
    Thread thrd = new Thread(new MyThread(), "MyThread #1");
    Thread thrd2 = new Thread(new MyThread(), "MyThread #2");
    thrd.start();
    Thread.sleep(1000);/*  w  w w  .  j  av  a2s.c o  m*/
    thrd.interrupt();
    thrd2.start();
    Thread.sleep(4000);
    thrd2.interrupt();
}

From source file:Wake.java

public static void main(String args[]) {
    Wake queue = new Wake();
    Runnable r = new RunThis(queue);
    Thread t;
    for (int i = 0; i < 10; i++) {
        t = new Thread(r);
        t.start();
    }//from w  w  w . jav a 2 s .  co m

    for (int i = 0; i < 11; i++) {
        try {
            Thread.sleep((long) (Math.random() * 1000));
        } catch (InterruptedException e) {
        }
        System.out.println("About to wake one thread");
        queue.wakeOne();
    }
}

From source file:FutureTest.java

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): ");
    String directory = in.nextLine();
    System.out.print("Enter keyword (e.g. volatile): ");
    String keyword = in.nextLine();

    MatchCounter counter = new MatchCounter(new File(directory), keyword);
    FutureTask<Integer> task = new FutureTask<Integer>(counter);
    Thread t = new Thread(task);
    t.start();
    try {// ww w  .jav  a2 s  .c om
        System.out.println(task.get() + " matching files.");
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
    }
}