App Engine 上的同步
我正在使用 Google App Engine 构建一个应用程序。该应用程序由多个 Servlet 组成,其中之一具有一个保存大量内部状态的静态成员对象。多个 Android 手机联系此 servlet,导致 servlet 更新静态成员对象的状态。但是,当多部手机同时与服务器通信时,我会遇到同步问题,其中静态对象同时被多个线程修改。我尝试过添加一些同步块,但这似乎没有帮助。
我认为原因与 App Engine 如何为 HTTP 请求生成线程有关,但我不确定。在 App Engine 中同步访问共享对象的标准方法是什么?谢谢!
I'm building an application using Google App Engine. The application consists of several servlets, one of which has a static member object that holds a lot of internal state. Multiple Android phones contact this servlet, causing the servlet to update the state of the static member object. However, when multiple phones happen to talk to the server at the same time, I get synchronization issues in which the static object is being modified by multiple threads at once. I've tried throwing in some synchronized blocks, but this does not seem to help.
I think the reason has something to do with how App Engine spawns threads for HTTP requests, but I'm not sure. What's the standard way to synchronize access to shared objects in App Engine? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 GAE 应用程序可以在不同的服务器上启动,一次可以并且将会有几个实例。任何实例都可以随时启动或终止,无需事先通知。因此,任何内存状态都是无用的。
您必须使用 memcache 服务或数据库来代替。
Your GAE app can be started on different servers, there can be, and will be few instances at one time. Any instance can be started or killed at any time, without any notice before. So, any in-memory state is useless.
You have to use or memcache service, or database instead.