| 1 | package cn.itcast_06; |
| 2 | |
| 3 | public 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected