Thread.sleep和Object.notify

public class SleepWaitTest extends Thread {
@Override
public void run() {
synchronized (this) {
System.out.println(Thread.currentThread().getName() + ":" + System.currentTimeMillis());
for (int i=0;i< 100;i++) {
if (i<99) {
System.out.println(Thread.currentThread().getName() + ":" + i);
try {
if (Thread.currentThread().getName().equals("Thread-1") && i==10) {
wait(1L);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
System.out.println(Thread.currentThread().getName() + ":" + System.currentTimeMillis());
}
}

public static void main(String[] args) throws InterruptedException {
    SleepWaitTest sleepWaitTest = new SleepWaitTest();
    new Thread(sleepWaitTest).start();
    new Thread(sleepWaitTest).start();

}

}

你可能感兴趣的:(Thread.sleep和Object.notify)