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

Method run

day24/code/day24_Thread/src/cn/itcast_05/SetThread.java:12–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10 }
11
12 @Override
13 public void run() {
14 while (true) {
15 synchronized (s) {
16 if (s.flag) {
17 // ��ͱ�ʾ������
18 try {
19 s.wait(); // t1�͵ȴ���
20 } catch (InterruptedException e) {
21 e.printStackTrace();
22 }// ��������ȴ�
23 }
24
25 if (x % 2 == 0) {
26 s.name = "����ϼ";
27 s.age = 28;
28 } else {
29 s.name = "����";
30 s.age = 31;
31 }
32 x++; // x=1,x=2
33
34 // ������ʾ
35 s.flag = true;
36 s.notify(); // ���ѵȴ����̣߳������������߳��ܹ�������ȡCPU��ִ��Ȩ
37 }
38 // t1,t2��
39 }
40 }
41
42}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected