一、使用两个线程循环打印出1~100 首先创建一个num类,该类的成员用于线程同步。 public class Num { int i; boolean falg; } 1. 2. 3. 4. 使用wait/notify机制+条件判断实现 public class TestThread1 { public static void main(String[] args) { Num num=new Num(); Thread t1=new Thread(new A...
zoukankan html css js c++ java 三个线程交替打印1到100public class Test { volatile int i = 1; public static void main(String[] args) throws Exception { Test obj = new Test(); Runnable runnable = new Runnable() { @Override public void run() { while (obj.i <= 100) { // 上锁...