List of usage examples for java.lang Thread Thread
public Thread(Runnable target, String name)
From source file:Main.java
public static void main(String[] args) { ThreadGroup group = new ThreadGroup("admin"); Thread t = new Thread(group, "website"); System.out.println("Threadgroup = " + group.getName()); String str = group.toString(); System.out.println(str);//from w w w. jav a 2 s . c o m }
From source file:Main.java
public static void main(String a[]) throws Exception { MyThread tt1 = new MyThread(50); MyThread tt2 = new MyThread(75); Thread t1 = new Thread(tt1, "Test thread 1"); Thread t2 = new Thread(tt2, "Test thread 2"); t1.start();/*w w w . j a v a 2 s. c o m*/ t2.start(); t1.join(); t2.join(); }
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 . j av a2 s . c o m System.out.println("thread = " + t); t.start(); }
From source file:ThreadDemo.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo(), "java2s.com thread"); // set thread priority t.setPriority(1);//from w w w . ja v a 2s. co m // print thread created System.out.println("thread = " + t); // this will call run() function t.start(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Thread previousThread = null; for (int i = 0; i < 20; i++) { JobRunnable job = new JobRunnable(i, previousThread); Thread thread = new Thread(job, "T-" + i); thread.start();//from w ww . j a v a2 s.c o m previousThread = thread; } if (previousThread != null) { previousThread.join(); } System.out.println("Program done."); }
From source file:ThreadDemo.java
public static void main(String args[]) { Thread currThread = Thread.currentThread(); // thread created Thread t = new Thread(new ThreadDemo(), "java2s.com thread"); System.out.println("current thread = " + currThread); System.out.println("thread created = " + t); // this will call run() function t.start();// w ww .j a v a 2 s.c o m }
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 w w w . j a v a2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { final ThreadGroup threadGroup = new ThreadGroup("workers"); ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(threadGroup, r); }/*from www . j a va2 s.c o m*/ }); System.out.println(threadGroup.activeCount()); }
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();//from w ww . ja v a 2 s . c om Thread.sleep(100); thrd.interrupt(); thrd2.start(); Thread.sleep(400); thrd2.interrupt(); }
From source file:RunnableThread.java
public static void main(String[] args) { for (int i = 1; i <= 5; i++) new Thread(new RunnableThread(), "" + i).start(); // Output is like SimpleThread.java }