1 Star 0 Fork 0

Java45_张奭/第四章 多线程

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Site16.java 702 Bytes
一键复制 编辑 原始数据 按行查看 历史
package hekh.duoxiancheng0926;
public class Site16 implements Runnable{
private int count = 10;
private int num = 0;
private boolean flag = false;
@Override
public void run() {
while(!flag){
sale();
}
}
private synchronized void sale() {
if(count<= 0){
flag = true;
return;
}
num++;
count--;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+"抢到第"+num+"张票,剩余"+count+"张票!");
}
public static void main(String[] args) {
Thread t = new Thread(new Site16());
t.start();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangshi66/DiSiZhang-DuoXianCheng.git
[email protected]:zhangshi66/DiSiZhang-DuoXianCheng.git
zhangshi66
DiSiZhang-DuoXianCheng
第四章 多线程
master

搜索帮助