zoukankan      html  css  js  c++  java
  • 多线程 Runnable 实现线程 内部类

    public class ThreadDemo4 {
        public static void main(String[] args){
            System.out.println(Thread.currentThread().getName());//main
            Thread.currentThread().setName("haha");
            String name = Thread.currentThread().getName(); // haha
            Thread t = Thread.currentThread();
            System.out.println(t.getPriority());// 5   线程默认优先级是 5
            t.setPriority(10); // 设置优先级 1 - 10
            System.out.println(t.getPriority());
            System.out.println(name);
    
    
            MyRunable m1 = new MyRunable();
            Thread t1 = new Thread(m1);
            t1.start();
            System.out.println(t1.getName()); //Thread-0
    
    
    
    
            // 匿名内部类对象实现
            new Thread(
                    new Runnable(){
                        public void run(){
                            System.out.println(Thread.currentThread().getName());//Thread-1
                            System.out.println("我是匿名内部类");
                        }
                    }
            ).start();
            
    
            //匿名类
            new Thread(){
                public void run(){
                    System.out.println(Thread.currentThread().getName());//Thread-2
                    System.out.println("匿名类"); 
                }
            }.start();
    
    
        }
    }
    
    
    
    //Runable 接口 实现线程
    
    class MyRunable implements Runnable{
        public void run(){
           System.out.println("helloworld");
        }
    }
    
    
  • 相关阅读:
    redis client 2.0.0 pipeline 的list的rpop bug
    Python解释器镜像源修改
    全连接层
    测试(张量)- 实战
    数据加载
    Python之微信-微信好友头像合成
    高阶操作
    MYSQL 查询缓存
    SQL Server 查看指定表上的索引
    MYSQL 查看表上索引的 1 方法
  • 原文地址:https://www.cnblogs.com/jijizhazha/p/7763715.html
Copyright © 2011-2022 走看看