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同步公共资源的更好方法?考虑资源应该被延迟初始化。
感谢, 阿德里安