• Runnable优先级


      

    package workhome;
    
    public class ThreadPriority {
        public static void main(String[] args) {
            MyThread a= new MyThread("S");
            System.out.println(a.getPriority());
            a.setPriority(10);
            MyThread b=new MyThread("B");
            b.setPriority(1);
            
            a.start();
            b.start();
        }
    }
    
    class MyThread extends Thread{
        private String name;
        public MyThread(String name) {
            this.name=name;
        }
        
        public void run() {
            System.out.println(name);
        }
    }
    优先级
    package workhome;
    
    public class Runnable2 {
        public static void main(String[] args) {
        
            /*
            new Thread(new Runnable() {
                public void run() {
                    for(int i=0;i<10;i++) {
                        System.out.println(i);
                    }
                }
            }).start();
            */
            new Thread() {
                public void run() {
                    for(int i=0;i<100;i++) {
                        System.out.println(i);
                    }
                }
            }.start();
        }
    }
    匿名类实现
    package workhome;
    
    public class Runnable1 {
    public static void main(String[] args) {
            Runnable r=new Dog();
            new Thread(r).start(); 
    }
    }
    
    class Animal{
        private String name;
        public String getName() {
            return name;
        }
        public void setName(String anme) {
            this.name=name;
        }
    }
    
    //Dog
    class Dog extends Animal implements Runnable{
        public void eat() {
            System.out.println("like bone!");
        }
        
        public void run() {
            eat();
        }
    }
    Runnable接口让普通类实现多线程
  • 相关阅读:
    构建之法阅读笔记05
    构建之法阅读笔记04
    构建之法阅读笔记03
    第九周学习进度条
    个人冲刺
    第八周进度条
    Git疑难解决
    Git常用命令
    git配置SSH公钥
    Laravel框架中如何使用 Presenter 模式?
  • 原文地址:https://www.cnblogs.com/King-boy/p/10990619.html
Copyright © 2020-2023  润新知