14 线程属性

package thread;

public class TestThree {

    /**
     * 线程属性:
     * 线程优先级,守护线程,线程组,未捕获异常的处理器
     * 
     * 
     * 线程优先级
     * public static final int MIN_PRIORITY = 1; //最小优先级
     * public static final int NORM_PRIORITY = 5; //默认优先级
     * public static final int MAX_PRIORITY = 10;//最大优先级
     * 
     * public static native void yield(); 当前线程让步,如果其他线程与此线程有同样的优先级,这些线程将会被调度
     * 
     * 
     * 守护线程
     *  public final void setDaemon(boolean arg0) {}  
     *  在线程启动之前设置为守护线程,为其他线程提供服务,当只剩下守护线程的时候,虚拟机就会退出。
     *  守护线程不应该访问固有资源,如,文件,数据库。它将会在任何时候中断,甚至在一个操作的中间中断。
     *  
     *  
     *  替换 处理器可以使用日志 API 发送未捕获异常的报告到日志文件
     *  
     *  
     *   //为所有的线程设置一个异常处理器
     *   public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler arg) {}
     *   
     *   
     *   //设置获取获取未捕获的异常处理器,则将线程组对象作为处理器
     *   public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler() {}
     *   
     *   
     *   
     *   //当一个线程因未捕获异常而终止, 按规定要将客户报告记录到日志中。
     *   // 参数:t 由于未捕获异常而终止的线程  e未捕获的异常对象 
     *   void UncaughtException(Thread t, Throwable e) 
     *   
     *   
     *    
     */
    
    
    public static void main(String[] args) {
        Thread t1 =  Thread.currentThread(); 
        t1.yield(); 
        t1.setDaemon(true); 
        t1.getUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(Thread.getDefaultUncaughtExceptionHandler());
        
        
        
    }
}
原文地址:https://www.cnblogs.com/lxh520/p/8445249.html