线程初学
2016-05-02 18:58
197 查看
1.哈尔滨火车站下面有三个火车票代售点,假如哈尔滨到北京的火车票总共是200张,如何用程序来实现三个售票点同时卖票的功能。
package Tread; class PP implements Runnable{ public int tickets=200; String str=new String("123"); public void run(){ while(true){ synchronized(this.str){ if(tickets>0){ System.out.println(Thread.currentThread().getName()+"卖出去的票数是:"+tickets--); } else { break; } } } } } public class Threade_14 { public static void main(String[] args) { PP pp =new PP(); Thread tt1=new Thread(pp); Thread tt2=new Thread(pp); Thread tt3=new Thread(pp); tt1.start(); tt2.start(); tt3.start(); } }
相关文章推荐
- iOS中代码性能测试的方法
- LeetCode:Reverse Vowels of a String
- mac安装Homebrew
- 多线程
- 联合线程
- 道格拉斯-普克 Douglas-Peuker(DP算法)-python实现
- eclipse https git
- php正则表达式和数组
- sprignmvc 中使用zyUpload 上传图片(批量)
- HDU 2795 Billboard
- HDU 2795 Billboard
- gitlab open ssl
- matlab usage: cellfun
- 搭建使用springmvc的web项目
- 从两地三中心到双活数据中心
- 基于bootstrap 模态框的警告框
- 5.简单的超链接的使用
- 回文串和镜像串和ctype.h
- Object-c------@property_and_@synthesize
- 判断一棵树是否是另一棵树的子树(C语言版)