📄 ex8_6.java
字号:
public class Ex8_6{ public static void main(String[] args) { SellTickets t=new SellTickets(); //新建一个售票类的对象 new Thread(t).start(); //用此对象作为参数创建3个新线程并启动 new Thread(t).start(); new Thread(t).start(); }}class SellTickets implements Runnable{ private int tickets=200; //将共享的资源作为私有变量 public void run() { while(tickets>0) //直到没有票可售为止 { System.out.println(Thread.currentThread().getName() +" is selling ticket "+tickets--); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -