1 //对当前对象加锁 2 public synchronized Object get(long mills) throws InterruptedException{ 3 long future = System.currentTimeMillis() + mills; 4 long remaining = mills; 5 //当超时大于0且result返回值不满足要求 6 while ((result == null) && remaining > 0){ 7 wait(remaining); 8 remaining = future - System.currentTimeMillis(); 9 } 10 return result; 11 } 12 }