穷人纠结于穷,却总是跳不出这个圈来
public synchronized void set(String name, int age){
if(!flag){
try {
super.wait();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
this.name = name;
try {
Thread.sleep(100);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
this.age = age;
flag = false;
super.notify();
}
public synchronized void get(){
if(flag){
try {
super.wait();
} catch (Exception e) {
// TODO: handle exception
}
}
try {
Thread.sleep(100);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
System.out.println(this.getName()+"<===>"+this.getAge());
flag = true;
super.notify();
}
1.使用Scanner工具类来获得用户输入的成绩信息,Scanner类位于java.util中,使用时需要导入此包import java.util.Scanner; 2.创建...