1
考慮一種情況,當我們有一個Controller使用2個使用相同控制器字段的操作方法。該字段應該被延遲初始化。Play中的字段同步!控制器
public class SomeController extends Controller {
private static volatile Resource resource;
private static Resource getResource() {
if (resource == null) {
synchronized (SomeController.class) {
if (resource == null) {
resource = new Resource();
}
}
}
return resource;
}
public static void action1() {
getResource().doSomeAction();
}
public static void action2() {
getResource().doSomeAnotherAction();
}
}
什麼是使用Play Framework同步公共資源的更好方法?考慮資源應該被延遲初始化。
感謝, 阿德里安