![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package lianxi.demo; public class Patient implements Runnable{ private int num; private int time; public Patient(){} public Patient(int num,int time){ this.num = num; this.time = time; } @Override public void run() { Thread t = Thread.currentThread(); for(int i =0; i<num;i++){ System.out.println("正在给第"+(i+1)+"位"+t.getName()+"病人看病!"); try { Thread.sleep(time); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println(t.getName()+"病人已看完病了!"); } }
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
package lianxi.demo; public class Main { public static void main(String[] args) { Patient p = new Patient(10, 1000); Thread t = new Thread(p, "特需号"); t.start(); t.setPriority(10); for (int i = 0; i < 50; i++) { if (i == 10) { try { t.join(); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("正在给第" + (i + 1) + "位普通病人看病!"); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("普通病人已全部看完!"); } }