首页 \ 问答 \ Google App Engine Cloud中会重置最终的静态变量(final static variables are reset in Google App Engine Cloud)

Google App Engine Cloud中会重置最终的静态变量(final static variables are reset in Google App Engine Cloud)

我有一个GWT + GAE网络应用程序,有几个服务和模块。 我正在使用mvp4g的模块功能。 我所有的服务扩展到:

public abstract class BaseServiceImpl extends RemoteServiceServlet {
 protected final static Map USERS = new HashMap();

我使用USERS来存储我当前的活动用户会话。 一旦我用户认证自己,我将他的会话ID存储为地图的关键字。

protected String getSessionId() {
    return getThreadLocalRequest().getSession().getId();
}

public String authenticate(String username, String password) {
    ...
    ..
    .
   String id = getSessionId();
   synchronized( this ) {    
       users.put(id, user);
   } 
   ...
   ..
   .

对于每个请求,我检查用户会话是否仍然有效。

protected boolean validUserSession() {  
    if(getThreadLocalRequest() == null) {
     logger.log(Level.SEVERE, "Thread is null");
     return false;
 } else if(getThreadLocalRequest().getSession() == null) {
     logger.log(Level.SEVERE, "Session is null");
     return false;
 }
 String id = getSessionId();
 UserJDO user = (UserJDO) users.get(id);
 if(user==null) {   
     logger.log(Level.SEVERE, "User is null");
     return false;
 }
 return true;
}

我启用了会话。 接下来我发布appengine-web.xml的最后几行

...
..
.
<sessions-enabled>true</sessions-enabled>
</appengine-web-app>

在开发服务器中一切正常。 但是,当我将它部署到谷歌应用引擎云时, 用户变量会针对每个请求进行重置。

任何人都可以解释我发生了什么? 我应该如何继续? 我应该将用户会话存储在数据存储中吗?


I have a GWT+GAE web app with several service and modules. I am using the module functionlity of mvp4g. All of my services extends:

public abstract class BaseServiceImpl extends RemoteServiceServlet {
 protected final static Map USERS = new HashMap();

I use USERS to store my current active user sessions. Once I user authenticates himself I store his session id as a key of the map.

protected String getSessionId() {
    return getThreadLocalRequest().getSession().getId();
}

public String authenticate(String username, String password) {
    ...
    ..
    .
   String id = getSessionId();
   synchronized( this ) {    
       users.put(id, user);
   } 
   ...
   ..
   .

For every request, I check if the user session is still valid.

protected boolean validUserSession() {  
    if(getThreadLocalRequest() == null) {
     logger.log(Level.SEVERE, "Thread is null");
     return false;
 } else if(getThreadLocalRequest().getSession() == null) {
     logger.log(Level.SEVERE, "Session is null");
     return false;
 }
 String id = getSessionId();
 UserJDO user = (UserJDO) users.get(id);
 if(user==null) {   
     logger.log(Level.SEVERE, "User is null");
     return false;
 }
 return true;
}

I have sessions enabled. Next I post the last lines of appengine-web.xml

...
..
.
<sessions-enabled>true</sessions-enabled>
</appengine-web-app>

Everything works fine in the Development server. However, when I deploy it to the google app engine cloud the users variable is reset for every request.

Can anyone explain me what it is happening? How should I proceed? Should I store the user sessions in the datastore?


原文:https://stackoverflow.com/questions/3545554
更新时间:2024-04-22 22:04

最满意答案

while true; do foo; sleep 2; done

顺便说一下,如果您在命令提示符下键入多行(正如您所显示的),然后使用箭头向上调用历史记录,则可以在单行上正确地标记。

$ while true
> do
>    echo "hello"
>    sleep 2
> done
hello
hello
hello
^C
$ <arrow up> while true; do    echo "hello";    sleep 2; done

while true; do foo; sleep 2; done

By the way, if you type it as a multiline (as you are showing) at the command prompt and then call the history with arrow up, you will get it on a single line, correctly punctuated.

$ while true
> do
>    echo "hello"
>    sleep 2
> done
hello
hello
hello
^C
$ <arrow up> while true; do    echo "hello";    sleep 2; done

相关问答

更多
  • while true; do foo; sleep 2; done 顺便说一下,如果您在命令提示符下键入多行(正如您所显示的),然后使用箭头向上调用历史记录,则可以在单行上正确地标记。 $ while true > do > echo "hello" > sleep 2 > done hello hello hello ^C $ while true; do echo "hello"; sleep 2; done while true; do foo; sl ...
  • 这将读取STDIN并使用shell引用将这些行解析为参数: # Clean input of potentially dangerous characters. If your valid input # is restrictive, this could instead strip everything that is invalid # s/[^a-z0-9" ]//gi sed -ue 's/[][(){}`;$]//g' | \ while read input; do if [ "x$inp ...
  • 哇,有一个更简单,更简洁的方法来实现这一点,而不必弄乱IFS变量或使用数组。 您可以使用“for”来执行此操作: 首先,我创建了一个与您的结构相同的文件: $ cat file id|lastName|Douglas|gender|birthday|joinDate|IP|browser id|lastName|Tim|gender|birthday|joinDate|IP|browser id|lastName|Andrew|gender|birthday|joinDate|IP|browser id|l ...
  • 答案是递归1 。 你有效地做了: foo() { echo something foo } 您可能希望将函数名称更改为其他名称。 或者,您可以通过以下方式来抑制shell函数查找: command lipo $SDK_DIR/lib/$CONFIG-iphoneos/$BASELIBNAME $SDK_DIR/lib/$CONFIG-iphonesimulator/$BASELIBNAME -create -output $OUTLIB 代替 lipo $SDK_DIR/lib/$CONFIG- ...
  • 它是内置编辑器模板中的发射类属性。 这篇文章很好地解释了它们。 http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html It's an emitted class attribute from a built-in editor template. This article explains them quite well. http://bradwilson.typepa ...
  • /etc/init.d中的脚本应该启动和停止服务。 所以他们需要准备好接受命令行参数的start和stop 。 (如果他们也接受像restart和status这样的论点,那就是奖金。) 当您将符号链接放在/etc/rcN.d目录中的其中一个脚本中时,将使用参数start或stop调用该脚本: 在启动时,参数取决于符号链接的名称是以S ( start )还是K ( stop - 字母代表“kill”)开头。 关闭时,参数将stop 。 (以上是debian行为,摘自Debian政策手册 。) 您的脚本不是此格 ...
  • 您可以使用command命令或其快捷方式符号\ 。 由于cd是内置的,你也可以使用builtin命令。 它们忽略函数和别名,而是直接在$PATH和/或内置函数中查找可执行文件。 $ alias ls='echo no ls for you!' $ ls no ls for you! $ command ls [directory listing] $ \ls [directory listing] You can use the command command, or its shortcut notat ...
  • 在条件中你需要-a而不是-o 。 你希望在它是Y或y时终止,即它应该运行而它不是Y并且它不是y 。 另外,在bash中你可以使用[[条件并使用右侧的模式: while [[ $option != [Yy] ]] You need -a instead of -o in the condition. You want to terminate when it's Y or y, i.e. it should run while it's not Y AND it's not y. Also, in bash ...
  • 使用标准输入的read读取。 当您在重定向中使用read ,它不会从键盘读取,它会从当时的任何标准输入读取。 CF卡: { read a echo $a } < <(echo Hello) 您可以在其他位置复制标准输入,以便能够同时处理多个流: exec 3<&0 # fd3 now points to the initial stdin { read a # This reads the "Hello". read b <&3 # ...
  • 我能够修复perl错误,并且经过一些修改后,bash脚本似乎现在运行良好。 但是,似乎这将是运行测试套件的更安全的方式,以防将来发生类似的情况: #!/bin/bash WHITE="\033[0m" GREEN="\033[32m" RED="\033[31m" run_full_test > out.txt 2>&1 & tail -f out.txt | while IFS= read line; do printf "%$(tput cols)s\r" " "; printf "% ...

相关文章

更多

最新问答

更多
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 高考完可以去做些什么?注意什么?
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • Flask中的自定义中止映射/异常(Custom abort mapping/exceptions in Flask)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 怎么在《我的世界》游戏里面编程
  • .NET可移植可执行文件VS .NET程序集(.NET Portable Executable File VS .NET Assembly)
  • 搜索字符串从视图中键入两个字段的“名字”和“姓氏”组合(Search Strings Typed from View for Two Fields 'First Name' and 'Last Name' Combined)
  • 我可以通过配置切换.Net缓存提供程序(Can I switch out .Net cache provider through configuration)
  • 在鼠标悬停或调整浏览器大小之前,内容不会加载(Content Does Not Load Until Mouse Hover or Resizing Browser)
  • 未捕获的TypeError:auth.get不是函数(Uncaught TypeError: auth.get is not a function)
  • 如何使用变量值创建参数类(How to create a parameter class with variant value)
  • 在std :: deque上并行化std :: replace(Parallelizing std::replace on std::deque)
  • 单元测试返回Connection对象的方法(Unit Test for a method that returns a Connection object)
  • rails:上传图片时ios中的服务器内部错误(rails: server internal error in ios while uploading image)
  • 如何在Android中构建应用程序警报[关闭](How build an application Alarm in Android [closed])
  • 以编程方式连接到Windows Mobile上的蓝牙耳机(Programmatically connect to bluetooth headsets on Windows Mobile)
  • 在两个不同的SharedPreference中编写并获得相同的结果(Writing in two different SharedPreference and getting the same result)
  • CSS修复容器和溢出元素(CSS Fix container and overflow elements)
  • 在'x','y','z'迭代上追加数组(Append array on 'x', 'y', 'z' iteration)
  • 我在哪里可以看到使用c ++源代码的UML方案示例[关闭](Where I can see examples of UML schemes with c++ source [closed])
  • SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
  • 位字段并集的大小,其成员数多于其大小(Size of bit-field union which has more members than its size)
  • 我安装了熊猫,但它不起作用(I installed pandas but it is not working)
  • Composer - 更改它在env中使用的PHP版本(Composer - Changing the version of PHP it uses in the env)
  • 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)
  • 函数调用可以重新排序(Can function calls be reordered)
  • 关于“一对多”关系的NoSQL数据建模(NoSQL Data Modeling about “one to many” relationships)
  • 如何解释SBT错误消息(How to interpret SBT error messages)
  • 调试模式下的Sqlite编译器错误“初始化程序不是常量”(Sqlite compiler errors in Debug mode “initializer is not a constant”)