• 17,优先级 yeiled方法


    package songyan;
    /*
     * 线程组(很少使用):一般线程是由谁创建的就是那个组
     * 例:主线程创建t1,t2,那么t1,t2的组就是main
     * 组也可以修改,使用ThreadGroup
     * 
     * 优先级(Priority):抢资源的频率
     * 线程的优先级:1-10
     * t1.setPriority(10);
     * 三个常量:
     * 1:MIN_PRIORITY
     * 10:MAX_PRIORITY
     * 5:NORM_PRIORITY
     * 
     * 共享变量用静态
     * 固定数据用常量
     * 
     * yield()【用的很少,面试题会出】:强制释放执行权(临时停止)
     * 暂停当前执行的线程对象
     * 现象:稍微减缓线程的运行,达到所有线程都能执行到的效果
     * 
     */
    class Demo implements Runnable{
        public void run()
        {
            while(true)
            {
                    for( int i=0;i<60;i++)
                    {
                        System.out.println(Thread.currentThread().getName()+"***"+i);
                        Thread.yield();
                    }
            }
            
        }
    }
    public class test{
        public static void main(String[] args) {
            Demo d= new Demo();
            Thread t1= new Thread(d);
            Thread t2 = new Thread(d);
    //        t1.setPriority(10);        
            t1.start();
            t2.start();
        }
    }
  • 相关阅读:
    Keep at Most 100 Characters
    Larry and Inversions
    计算指数
    简单题
    重要的话说三遍
    I Love GPLT
    猜数字
    打印沙漏
    多态性(polymorphism),封装性(encapsulation),内聚(cohesion)以及耦合(coupling)的基本概念
    Hibernate面试题
  • 原文地址:https://www.cnblogs.com/exexex/p/8435400.html
Copyright © 2020-2023  润新知