List of usage examples for java.lang Thread Thread
public Thread(String name)
From source file:Main.java
public static void main(String args[]) throws Exception { Thread t = new Thread(new ThreadDemo()); t.start();//from ww w . ja v a2 s . c om // waits for this thread to die t.join(); 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();// w w w. j a v a 2s.c o m t.join(2000, 500); //after waiting for 2000 milliseconds plus 500 nanoseconds ... System.out.print(t.getName()); System.out.println(", status = " + t.isAlive()); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Thread t = new Thread(Main::run); t.start();// w w w.j a v a 2 s .c om Thread.sleep(5000); t.interrupt(); }
From source file:Main.java
public static void main(String args[]) throws Exception { Thread t = new Thread(new ThreadDemo()); t.start();//w w w .j av a 2s . c om // waits at most 2000 milliseconds for this thread to die. t.join(2000); // 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) { // Create a Thread object Thread t = new Thread(Main::print); // Start the thread t.start();/*from www . j a v a2s . com*/ }
From source file:Uncaught.java
public static void main(String[] args) { Thread thread = new Thread(new Uncaught()); thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { e.printStackTrace();/*from ww w . j av a 2 s. co m*/ } }); thread.start(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Thread thread1 = new Thread(new TestThread(1)); Thread thread2 = new Thread(new TestThread(2)); thread1.start();// ww w . j a v a 2 s .com thread2.start(); thread1.join(); thread2.join(); }
From source file:Main.java
public static void main(String[] args) { // Create two Thread objects Thread t1 = new Thread(Main::print); Thread t2 = new Thread(Main::print); // Start both threads t1.start();/*w w w. j a v a2 s .c om*/ t2.start(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Thread thread1 = new Thread(new TestThread(1)); Thread thread2 = new Thread(new TestThread(2)); thread1.setPriority(Thread.MAX_PRIORITY); thread2.setPriority(Thread.MIN_PRIORITY); thread1.start();//ww w . j av a 2s. c o m thread2.start(); thread1.join(); thread2.join(); }
From source file:Main.java
public static void main(String[] args) { Thread t = new Thread(() -> { while (true) { updateBalance();/*from w ww . j av a 2 s . co m*/ } }); t.start(); t = new Thread(() -> { while (true) { monitorBalance(); } }); t.start(); }