//类实现接口
public class Processor implements Runnable {
// 重写接口方法
@Override
public void run() {
for (int i = 0; i <= 100; i++) {
System.out.println(Thread.currentThread().getName() + "*****************" + i);
}
}
}
---------------------------
package charpter06;
/**
* Thread类中的join方法
*/
public class TestJoin {
public static void main(String[] args) {
// 创建对象
Processor p = new Processor();
// 创建一个线程对象
Thread t1 = new Thread(p, "A");
t1.start();
// 创建对象,并传对象
Thread t2 = new Thread(p, "B");
t2.start();
try {
t1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("---------main方法--------");
}