多线程
来源:互联网 发布:2015年贵州旅游数据 编辑:程序博客网 时间:2024/06/05 15:55
//使用同步方法
publicclass Test5{
publicstaticvoid main(String[]args) {
MyThread mt = new MyThread();
new Thread(mt,"A").start();
new Thread(mt,"B").start();
new Thread(mt,"C").start();
}
}
class MyThreadimplements Runnable{
privateintticket = 10;
@Override
publicvoid run() {
for(inti = 0 ; i < 20 ;i++){
this.sale();
}
}
publicsynchronizedvoid sale(){ 同步方法
if(this.ticket > 0){
try {
Thread.sleep(100);
} catch (InterruptedExceptione) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+"saleticket=" +this.ticket--);
}
}
}- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 2-8连接到LDAP
- linux安装fcitx
- 练习 3-6 修改itoa函数,使得该函数可以接收三个参数。其中,第三个参数为最小字段宽度。为了保证转换后所得的结果至少具有第三个参数指定的最小宽度,在必要时应在所得结果的左边填充一定的空格。
- linux源码安装mysql
- Camera app 分析(四)预览与滤镜
- 多线程
- 开发过程的三个阶段
- EffectiveC++学习笔记-条款43|44
- 排序算法之冒泡排序
- 如何用Linux装逼?
- websocket---前端的实现(一)
- Python框架——Flask
- Android动画机制与使用技巧(二)布局动画、插值器、自定义动画
- C# 实现 链表之背包、队列和栈