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); } } }