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

Class Student

day24/code/day24_Thread/src/cn/itcast_06/Student.java:3–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1package cn.itcast_06;
2
3public class Student {
4 private String name;
5 private int age;
6 private boolean flag = false; // ��ʾ�Ƿ�������
7
8 public synchronized void set(String name, int age) {
9 if (this.flag) {
10 try {
11 this.wait();
12 } catch (InterruptedException e) {
13 e.printStackTrace();
14 }
15 }
16
17 this.name = name;
18 this.age = age;
19
20 this.flag = true;
21 this.notify();
22 }
23
24 public synchronized void get() {
25 if (!this.flag) {
26 try {
27 this.wait();
28 } catch (InterruptedException e) {
29 e.printStackTrace();
30 }
31 }
32
33 System.out.println(this.name + "---" + this.age);
34
35 this.flag = false;
36 this.notify();
37 }
38}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected