• java158-线程的常用方法yield,优先级


        //线程
        public class test102 extends Thread{
            public void run(){
                while (true){
                    System.out.println("我是线程1"+this.getName());
                    try {
                        Thread.sleep( 1000 );
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }
                }
            }
        }

        //线程
        public class test103 extends Thread{
            public void run(){
                while (true){
                    System.out.println("我是线程2"+this.getName());
                    try {
                        Thread.sleep( 1000 );
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }
                }
            }
        }

    测试类

        public class test105 {
            public static void main(String[] args){
                test102 one=new test102();
                test103 two=new test103();
                one.setName("线程1");
                one.setName( "线程2" );
                //设置线程的优先级
                two.setPriority( Thread.MAX_PRIORITY );
                one.setPriority( Thread.MIN_PRIORITY );
                //线程暂停thread.yield
                one.start();
                two.start();
                System.out.println( "我是主方法" );
            }
        }

  • 相关阅读:
    JS原型对象prototype
    元数据的前世今生
    6 MySQL常用的数据类型
    容器_Docker ( 06 )
    SpringBoot 使用 Sa-Token 的全局过滤器解决跨域问题
    网格(grid)布局
    react嵌套路由
    Spring对事务的实现
    05-SA8155 QNX SPI 全双工通讯
    Android:使用Jetpack Compose画渐变背景
  • 原文地址:https://blog.csdn.net/qq_41632427/article/details/125474319