两个线程交替输出1-100
方法一:使用类锁
public class JiOuTest {
public static void main(String[] args) {
PrintThread p=new PrintThread();
Thread t1=new Thread(p);
Thread t2=new Thread(p);
t1.start();
t2.start();
}
}
// 类锁
class PrintThread implements Runnable {
private static Object lock = new Object();
private static int num = 0;
@Override
public void run() {
synchronized (lock) {
while