zoukankan      html  css  js  c++  java
  • 类Thread

    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());
    	}
    }
    
  • 相关阅读:
    CSS 兼容 总结
    IF IE
    取消chrome浏览器下input和textarea的默认样式
    左右浮动边距为0,中间间隔一定
    标题右边10px位置紧跟发布时间
    两款CSS3样式可视化在线生成工具
    文字截取,多余文字用省略号(...)代替
    O
    N
    M
  • 原文地址:https://www.cnblogs.com/denggelin/p/6345133.html
Copyright © 2011-2022 走看看