package ldb0715.night.demo04.thread;
public class MyThread extends Thread {
/**
* 1.卖400张票,创建4个线程各自卖100 thread
*/
private int ticket = 100;
int j = 0;
@Override
public void run() {
for (int i = 100; i >0; i--) {
ticket--;
j++;
System.out.println("==="+Thread.currentThread().getName()+
"==卖了"+j+"张票,还剩下:="+ticket+"张票=============");
}
}
}
package ldb0715.night.demo04.thread;
public class TestThread {
public static void main(String[] args) {
/**
* .卖400张票,创建4个线程各自卖100 thread
*/
MyThread t1 = new MyThread();
MyThread t2 = new MyThread();
MyThread t3 = new MyThread();
MyThread t4 = new MyThread();
t1.setName("小小");
t2.setName("小一");
t3.setName("小二");
t4.setName("小三");
t1.start();
t2.start();
t3.start();
t4.start();
}
}
卖400张票,创建4个线程各自卖100 thread java
最新推荐文章于 2022-04-06 16:14:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)