本程序目的:解决卖重复票 还有 负数票的情况
来源:互联网 发布:巨浪金融研究所数据 编辑:程序博客网 时间:2024/05/21 22:25
package com.mth.synchronizedtest;/*多线程 * 本程序目的:解决卖重复票 还有 负数票的情况 * synchronized这个关键字有两种用法1、放方法名前形成同步方法;2、放在块前构成同步块。 * * */public class SynchronizedTest1 implements Runnable {private int tickets = 100;// @Override// public void run() {// for (int i = 0; i < 50; i++) {// // 第一种同步块 实现共享// synchronized (this) {//// if (tickets > 0) {//// System.out.println(Thread.currentThread().getName()// + "号窗口卖出" + this.tickets-- + "号票");//// }// }// }// }public synchronized void run() {// 第二种 方法同步for (int i = 0; i < 50; i++) {// 同步块 实现共享if (tickets > 0) {try {Thread.sleep(5);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}System.out.println(Thread.currentThread().getName() + "号窗口卖出"+ this.tickets-- + "号票");}}};public static void main(String[] args) {SynchronizedTest1 test = new SynchronizedTest1();Thread t1 = new Thread(test);Thread t2 = new Thread(test);Thread t3 = new Thread(test);Thread t4 = new Thread(test);t1.start();t2.start();t3.start();t4.start();}}
0 0
- 本程序目的:解决卖重复票 还有 负数票的情况
- 本BLOG的目的
- 重复造轮子的目的
- 如何解决Viz Ticker 3D的scroller重复情况
- [1.1.4] 本书的目的
- byte转int出现负数的情况
- 还有一种情况可能是,jar包重复了
- asp去掉有负数的重复数据
- 杭电2008统计正数负数还有零的个数
- 解决并发情况下库存减为负数问题
- 解决并发情况下库存减为负数问题
- 解决OC 字典根据Value找Key 重复和不重复的两种情况
- 编写一个程序,求输入数的平方根。设置异常处理,对输入负数的情况给出提示
- 引入内联函数的目的是为了解决程序中函数调用的效率
- MFC 还有值得注意的几个情况
- 本博客建立目的
- 本博客目的
- 我写的程序还有
- PhoneGap 03 平台支持
- C++平台对指针的处理
- gap and gatt
- 网众远程修改ip、dns
- vb教程:将Edraw Office ActiveX控件添加到Visual Basic 6.0项目
- 本程序目的:解决卖重复票 还有 负数票的情况
- iOS4层结构之Media层
- 对新员工的谈话
- 关于x64汇编调用api的问题
- 扩大Vmware虚拟机中Ubuntu系统磁盘空间的方法
- 请教汇编ALIGN伪指令的问题
- 0K6410学习之linux移植nand flash
- VB6 Switch和Choose的用法
- MySQL触发器Trigger实例篇