14.3 线程的实现方式二练习:买票
2016-05-27 16:00
260 查看
class SaleTicke implements Runnable { int k=10; //注意这里不用静态,因为只创建一个Runable子类的对象 public void run() { while(true) { synchronized("锁") { if(k>0) { System.out.println(Thread.currentThread().getName()+"卖了第"+k+"张"); k--; } else { System.out.println("票卖完了"); break; } } } } } class wu { public static void main(String [] args) { SaleTicke st1 = new SaleTicke(); Thread th1 = new Thread(st1,"窗口一"); Thread th2 = new Thread(st1,"窗口二"); Thread th3 = new Thread(st1,"窗口三"); th1.start(); th2.start(); th3.start(); } }
相关文章推荐
- Redis
- MFC中子控件响应键盘消息
- QT环境变量设置
- 再次写给我们这些浮躁的程序员
- Ubuntu 14.04升级系统内核
- TDD的iOS开发初步以及Kiwi使用入门
- Scrum 项目7.0——第一个Sprint的总结和读后感
- abs函数
- 期末设计(十三周)
- 极力推荐一款小巧玲珑的可视化编辑器bootstrap-wysiwyg
- 剑指Offer:合并2个排序的链表
- U盘装win7/win8 32位&64位系统
- 14.2 线程创建的方式二:
- Android中dp和px之间进行转换的代码
- 290. Word Pattern
- Save & Apply mechanism of luci
- IOS 单例设计模式解读
- 详解SQL Server连接(内连接、外连接、交叉连接)
- 26. SpringMVC_mvc_view-controller标签 (无笔记)
- 连接Oracle11g时报错ORA-12541: TNS: 无监听程序