forked from CentMeng/JavaFrameTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFutureDate.java
More file actions
42 lines (34 loc) · 1.01 KB
/
Copy pathFutureDate.java
File metadata and controls
42 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.msj.sync.future;
/**
* @author mengxiangcheng mengshaojie@188.com
* @date 2017/3/15 上午9:15
* @copyright ©2017 孟少杰 All Rights Reserved
* @desc Date包装类,用于存放真实数据
*/
public class FutureDate implements Date{
private RealDate realDate;
private boolean isReady = false;
public synchronized void setRealDate(RealDate realDate){
//如果已经装载完毕了,就直接返回
if(isReady){
return;
}
//如果没有装载,进行装载真实对象
this.realDate = realDate;
isReady = true;
//进行通知(很关键,配合wait(),)
notify();
}
@Override
public synchronized String getRequest() {
//如果没加载好,程序就一直阻塞状态
while(!isReady){
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return this.realDate.getRequest();
}
}