public Object get(long timeout){
synchronized (this){
//经过时间
long passtime=0;
//开始时间
long beginTime = System.currentTimeMillis();
//剩余等待时间, 为防止“虚假唤醒”,这一轮循环应该等待的时间
long timeleft=timeout-passtime;
while (reponse==null){
timeleft=timeout-passtime;
if (timeleft<=0){
System.out.println("超时");
break;
}
try {
this.wait(timeleft);
} catch (InterruptedException e) {
e.printStackTrace();
}
passtime=System.currentTimeMillis()-beginTime;
}
}
return reponse;
}
//生成对象
public void setReponse(Object object){
synchronized (this){
this.reponse=object;