public final void join()
throws InterruptedException
/* * public final void join() * throws InterruptedException * * 等待该线程终止。 * */ public class IntegerDemo { public static void main(String[] args) { myThread my1 = new myThread(); myThread my2 = new myThread(); myThread my3 = new myThread(); my1.setName("hello"); my2.setName("world"); my3.setName("java"); my1.start(); try { my1.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } my2.start(); my3.start(); } } class myThread extends Thread { public void run() { for (int i = 0; i < 10; i++) { System.out.println(getName() + ":" + i); } System.out.println(Thread.currentThread().getName()); } }
public final void setDaemon(boolean on)
/* * public final void setDaemon(boolean on) * * 将该线程标记为守护线程或用户线程。当正在运行的线程都是守护线程时,Java虚拟机退出。 * 该方法必须在启动线程前调用。 * */ public class IntegerDemo { public static void main(String[] args) { myThread my1 = new myThread(); myThread my2 = new myThread(); myThread my3 = new myThread(); my1.setName("hello"); my2.setName("world"); my3.setName("java"); my1.setDaemon(true); my1.start(); my2.start(); my3.start(); } } class myThread extends Thread { public void run() { for (int i = 0; i < 100; i++) { System.out.println(getName() + ":" + i); } System.out.println(Thread.currentThread().getName()); } }