jlm*_*564 0 google-app-engine synchronization instance
如果我有这样的课程:
public class Example
{
ArrayList<String> vector;
public Example singleton = new Example();
private Example()
{
//Read data from BD and fill the vector. Example vector: ["foo","voo","faa","vuu","vee"]
}
public synchronized removeElement()
{
vector.remove(0);
}
public synchronized changeElement()
{
vector.set(0,"fii");
}
}
Run Code Online (Sandbox Code Playgroud)
如果有多个实例在运行且其中一个实例执行该方法removeElement
,那么另一个实例的值会发生什么?如果其中一个执行该方法changeElement
?
GAE可以有多个并行运行的JVM实例,因此内存中的更新值只能在该实例上可见.
您应该使用共享数据存储:memcache(免费,快速,但易失性)或数据存储(成本高,速度慢,但一致).
归档时间: |
|
查看次数: |
421 次 |
最近记录: |