package z;
class MyThread extendsThread{
privateintticket = 10;
privateString name;
publicMyThread(String name){
this.name =name;
}
publicvoidrun(){
for(inti = 0; i < 500; i++){
if(this.ticket > 0){
System.*out*.println(this.name+"卖票---->"+(this.ticket--));
}
}
}
}
public classThreadDemo {
publicstaticvoidmain(String[] args) {
MyThread mt1= newMyThread("一号窗口");
MyThread mt2= newMyThread("二号窗口");
MyThread mt3= newMyThread("三号窗口");
mt1.start();
mt2.start();
mt3.start();
}
}
package z;
class MyThread1 implementsRunnable{
privateintticket =10;
publicvoidrun(){
for(inti = 0; i<500; i++){
if(this.ticket>0){
System.*out*.println(Thread.*currentThread*().getName()
+ "卖票---->"+ (this.ticket--));
}
}
}
}
public classRunnableDemo {
publicstaticvoidmain(String[] args) {
// 设计三个线程
MyThread1 mt = newMyThread1();
Thread t1 = newThread(mt, "一号窗口");
Thread t2 = newThread(mt, "二号窗口");
Thread t3 = newThread(mt, "三号窗口");
t1.start();
t2.start();
t3.start();
}
}
package z;
class MyThread1 implementsRunnable{
privateintticket = 10;
publicvoidrun(){
for(inti = 0; i<500; i++){
if(this.ticket>0){
try{
Thread.*sleep*(100);
System.*out*.println(Thread.*currentThread*().getName()
+ "卖票---->"+ (this.ticket--));
}catch(Exception e) {
e.printStackTrace();
}
}
}
}
}
public classRunnableDemo {
publicstaticvoidmain(String[] args) {
// 设计三个线程
MyThread1 mt = newMyThread1();
Thread t1 = newThread(mt, "一号窗口");
Thread t2 = newThread(mt, "二号窗口");
Thread t3 = newThread(mt, "三号窗口");
t1.start();
t2.start();
t3.start();
}
}
package z;
class MyThread1 implementsRunnable{
privateintticket = 1000;
publicvoidrun(){
for(inti = 0; i<5000; i++){
synchronized(this) {
if(this.ticket>0){
System.*out*.println(Thread.*currentThread*().getName()+"卖票---->"+(this.ticket--));
}
}
}
}
}
public classRunnableDemo {
publicstaticvoidmain(String[] args) {
// 设计三个线程
MyThread1 mt = newMyThread1();
Thread t1 = newThread(mt, "一号窗口");
Thread t2 = newThread(mt, "二号窗口");
Thread t3 = newThread(mt, "三号窗口");
t1.start();
t2.start();
t3.start();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有