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
最满意答案
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 ...
-
Bash Shell:无限循环(Bash Shell: Infinite Loop)[2023-10-28]
哇,有一个更简单,更简洁的方法来实现这一点,而不必弄乱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 ... -
Bash脚本迭代目录中的文件进入无限循环(Bash script iterating files in a directory goes into infinite loop)[2023-06-16]
答案是递归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- ... -
单线在哪里?(Where is the single-line?)[2022-04-12]
它是内置编辑器模板中的发射类属性。 这篇文章很好地解释了它们。 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 ... -
Bash脚本无限循环关闭(Bash script infinite loop shutdown)[2022-03-26]
/etc/init.d中的脚本应该启动和停止服务。 所以他们需要准备好接受命令行参数的start和stop 。 (如果他们也接受像restart和status这样的论点,那就是奖金。) 当您将符号链接放在/etc/rcN.d目录中的其中一个脚本中时,将使用参数start或stop调用该脚本: 在启动时,参数取决于符号链接的名称是以S ( start )还是K ( stop - 字母代表“kill”)开头。 关闭时,参数将stop 。 (以上是debian行为,摘自Debian政策手册 。) 您的脚本不是此格 ... -
在不创建无限循环的情况下向基本bash命令添加内容(Adding things to basic bash commands without creating infinite loops)[2022-06-28]
您可以使用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 "% ...