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

相关问答

更多

单行Bash无限while循环语法(Syntax for a single-line Bash infinite while loop)

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 fo...

从bash脚本到无限循环中的bash脚本(From bash script to bash script in infinite loop)

这将读取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 [ "...

Bash Shell:无限循环(Bash Shell: Infinite Loop)

哇,有一个更简单,更简洁的方法来实现这一点,而不必弄乱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...

Bash脚本迭代目录中的文件进入无限循环(Bash script iterating files in a directory goes into infinite loop)

答案是递归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/$CO...

单线在哪里?(Where is the single-line?)

它是内置编辑器模板中的发射类属性。 这篇文章很好地解释了它们。 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.t...

Bash脚本无限循环关闭(Bash script infinite loop shutdown)

/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)

您可以使用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 ...

在bash中无限循环[重复](Infinite while loop in bash [duplicate])

在条件中你需要-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脚本进入无限循环(My bash script gets into infinite loop)

使用标准输入的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 ...

这个bash脚本如何导致无限循环?(How is this bash script resulting in an infinite loop?)

我能够修复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" " "; prin...

相关文章

更多

深入浅出dwr系列教程之3.engine.js的功能详解

engine.js对DWR非常重要,因为它是用来转换和动态生成javascript的接口供函数调用的j ...

全球最流行的66款App的共同规律

根据苹果AppStore、Google Play、App Annie、亚马逊 AppStore及Win ...

最简单下拉刷新,Google最新(可刷新任何控件)

main_activity.xml代码: &lt;android.support.v4.widget. ...

十分钟了解分布式计算:Google Dataflow

介绍 Google Cloud Dataflow是一种构建、管理和优化复杂数据处理流水线的方法,集成 ...

基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果

随着微信的到来,二维码越来越火爆,随处能看到二维码,比如商城里面,肯德基,餐厅等等,对于二维码扫描我们 ...

微信公众平台如何与Web App结合?

Web App简而言之就是为移动平台而优化的网页,它可以表现得和原生应用一样,并且克服了原生应用一些固 ...

基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果(转)

转载:http://blog.csdn.net/xiaanming/article/details/1 ...

基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果

转载请注明出处:http://blog.csdn.net/xiaanming/article/deta ...

基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果

了解二维码这个东西还是从微信中,当时微信推出二维码扫描功能,自己感觉挺新颖的,从一张图片中扫一下竟然能 ...

最新问答

更多

python的访问器方法有哪些

使用方法: class A(object): def foo(self,x): #类实例方法 print "executing foo(%s,%s)"%(self,x) @classmethod def class_foo(cls,x): #类方法 print "executing class_foo(%s,%s)"%(cls,x) @staticmethod def static_foo(x): #静态方法 print "executing static_foo(%s)"%x调用方法: a =

使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)

我认为你必须将两个TableGetway传递给UserTable构造。 你必须改变Module.php看看: public function getServiceConfig() { return array( 'factories' => array( 'User\Model\UserTable' => function($sm) { $userTableGateway = $sm->get('UserTable

透明度错误IE11(Transparency bug IE11)

这是一个渲染错误,由使用透明度触发,使用bootstrap用于在聚焦控件周围放置蓝色光环的box-shadow属性。 可以通过添加以下类覆盖来解决它。 .form-control:hover { -webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); -moz-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); box-shadow: 0px 0px 4px 0px rgba(0,0,255,1)

linux的基本操作命令。。。

ls 显示目录 mkdir 建立目录 cd 进入目录

响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)

将z-index设置为.main-nav这将解决您的重叠问题 .main-nav { position:relative; z-index:9; } set z-index to .main-nav This will fix your overlaping issue .main-nav { position:relative; z-index:9; }

在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)

这是因为模式规范"a"打开一个文件以便追加,文件指针在末尾。 如果您尝试从此处读取,则由于文件指针位于EOF,因此没有数据。 您应该打开"r+"进行阅读和写作。 如果在写入之前读取整个文件,则在写入更多数据时,文件指针将正确定位以追加。 如果这还不够,请探索ftell()和fseek()函数。 That is because the mode spec "a" opens a file for appending, with the file pointer at the end. If you

NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)

支持空中接口的数据速率是一回事。 在消除协议开销,等待eeprom写入以及所有需要时间的其他内容之后,您看到的数据速率是完全不同的故事。 长话短说,从标签读取或进行对等传输时的实际数据速率峰值约为2.5千字节/秒。 取决于具体的标签或对等技术,它可能比这慢很多。 The supported data-rates of the air-interface are one thing. The data-rate that you see after removing protocol overhe

元素上的盒子阴影行为(box-shadow behaviour on elements)

它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂

Laravel检查是否存在记录(Laravel Checking If a Record Exists)

这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found

设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)

$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640