package ba; public class Tongbu implements Runnable{ int i=100; public void run(){ while(true){ sell(); } } public synchronized void sell(){ if(i>0){ System.out.println(Thread.currentThread().getName()+":"+i); i--; } } }
时间: 2024-10-11 04:52:51
package ba; public class Tongbu implements Runnable{ int i=100; public void run(){ while(true){ sell(); } } public synchronized void sell(){ if(i>0){ System.out.println(Thread.currentThread().getName()+":"+i); i--; } } }