MCPcopy Create free account
hub / github.com/DuGuQiuBai/Java / run

Method run

day23/code/day23_Thread/src/cn/itcast_09/MovieTicket.java:13–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11 private Demo d = new Demo();
12
13 @Override
14 public void run() {
15 while (true) {
16 // t1,t2,t3
17 // t1�����ˣ�������ͬ������������ǣ���ɫ���(���ϲ���������·�ĺ��̵�)
18 // t2,t3��ֻ��������ɵɵ�ĵȴ�
19 synchronized (this) {
20 // t1�ͽ����ˣ������޸ı��Ϊ��ɫ���
21 if (tickets > 0) {
22 // ��������ʵ���
23 try {
24 Thread.sleep(100); // t1��Ϣ��
25 } catch (InterruptedException e) {
26 e.printStackTrace();
27 }
28
29 System.out.println(Thread.currentThread().getName()
30 + "���ڳ��۵�" + (tickets--) + "��Ʊ");
31 }
32 }
33 // t1�����ˣ������޸ı��Ϊ��ɫ���
34 }
35 }
36}

Callers

nothing calls this directly

Calls 2

sleepMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected