Lev1

导航

模拟看病

package cn.DoctorVip;

public class VipThread implements Runnable{
    
    

    @Override
    public void run() {
        for(int i = 0;i < 10;i++) {
            Thread.currentThread().setName("VIP");
            String name = Thread.currentThread().getName();
            System.out.println(name+(i+1)+"正在看病");
            
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            
        }
        
    }

}
线程类
package cn.DoctorVip;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        VipThread vt = new VipThread();
        Thread vip = new Thread(vt,"VIP");
        vip.setPriority(10);
        vip.start();
        for(int i = 0;i <50;i++) {
            if(i ==10) {
                
                try {
                    vip.join();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            Thread.currentThread().setName("普通病人");
            String name = Thread.currentThread().getName();
            System.out.println(name+(i+1)+"正在看病");
            Thread.sleep(500);
        }
        
    }
}

 

posted on 2019-08-05 22:03  Lev1  阅读(184)  评论(0编辑  收藏  举报