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 }

 

posted on 2017-11-27 21:15  飞奔的菜鸟  阅读(222)  评论(0编辑  收藏  举报