java线程电话亭案例

record

在这里插入代码片
package java_tel_booth;
class dht{
	
}
class talker extends Thread{
	private dht a;
	private String name;
	private String[] s;
	talker(dht d,String name,String[] b){a=d;this.name=name;s=b;}
	public void run() {
		synchronized(a) {
			System.out.print(this.name+"正在使用电话亭:");
			for(String q:s) {
				System.out.print(q);
			}
			System.out.println();
		}
	}
}
public class App {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		dht a=new dht();
		String[] s1= {"1","2","3"};
		String[] s2= {"A","B","C","D","E"};
		String[] s3= {"你好,","我也好,","大家都好!"};
		talker t1=new talker(a,"张三",s1);
		talker t2=new talker(a,"李四",s2);
		talker t3=new talker(a,"王五",s3);
		t1.start();t2.start();t3.start();
	}

}

在这里插入图片描述
写得不是很好,请多指教 🤭

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值