package day01; public class VIPThread implements Runnable{ @Override public void run() { for(int i = 0;i<10;i++) { String name = Thread.currentThread().getName(); System.out.println(name+(i+1)+"正在看病"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } // TODO Auto-generated method stub } }
package day01; public class Main { public static void main(String[] args) { VIPThread vipThread = new VIPThread(); Thread vip = new Thread(vipThread,"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(); } } String name = Thread.currentThread().getName(); name= "普通患者"; System.out.println(name+(i+1)+"正在看病"); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }