0

如果我有这样的课程:

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");
    }
}

如果有多个实例在运行,其中一个执行了方法removeElement,那么另一个实例的值会发生什么?如果其中一个执行该方法changeElement

4

2 回答 2

5

GAE 可以有多个并行运行的 JVM 实例,因此更新内存中的值将仅在该实例上可见。

您应该使用共享数据存储:memcache(免费、快速但易失)或数据存储(昂贵、较慢但一致)。

于 2013-01-15T19:19:01.490 回答
1

App Engine 实例在单独的 JVM 上运行,因此它们每个都将在内存中具有单独的“向量”实例。要在这些之间同步状态,您需要使用共享状态服务,例如数据存储或内存缓存。

于 2013-01-15T19:03:13.963 回答