多线程驾校学车练习题
package com.cd.thread;
class VipStudent implements Runnable{
@Override
public void run() {
for (int i = 0; i <10 ; i++) {
System.out.println(i+"vip正在学车。。。。。");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class NormalStudent implements Runnable{
Thread vip ;
public NormalStudent(Thread vip) {
this.vip = vip;
}
public NormalStudent() {
}
@Override
public void run() {
for (int i = 0; i <10 ; i++) {
if (i==9){
try {
vip.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(i+"普通学员正在学车。。。。。");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public class ThreadDemo03 {
public static void main(String[] args) {
VipStudent vipStudent = new VipStudent();
Thread Vipthread = new Thread(vipStudent);
NormalStudent normalStudent = new NormalStudent(Vipthread);
Thread Normalthread = new Thread(normalStudent);
Vipthread.setPriority(Thread.MAX_PRIORITY);
Normalthread.setPriority(Thread.MIN_PRIORITY);
Vipthread.start();
Normalthread.start();
}
}