java - What is the lifespan of a private variable in an GAE Endpoint class? -


i have following code instant messenger style app.

public class myendpoint { private integer numberofconvos=0; ...} 

then update this:

@apimethod (name="creategroup") public mymodel creategroup(@named("profile") string profile){     numberofconvos=numberofconvos+1; } 

so everytime make new chat, can make unique , increasing id.

if redeploy backend (bug fix example) variable reset? not want store 1 token in datastore, because doesnt seem needed , datastore charges reads/writes.

if reset each time deploy, correct way keep track of variable?

if not reset when redeploy, how force reset?

a non-static variable initialized each thread. several threads can running on same app engine instance , cloud endpoint service can running on several instances in parallel.

so let's given current load, cloud endpoint service served through 3 instances i1, i2, i3. let's each instances run 5 threads. in case have 15 different versions of numberofconvos 15 different values.

keep in mind instances can turned on or off google @ time, in case service moved different instance. this reset numberofconvos variable.

to put more : java code should stateless, should not store state between requests in variable, static one.

you have 2 choices here :

  • if not want/need keep track of number of convos on server , want way uniquely identify each convo, use uuid class generate unique id each convo, low risk of collision. the documentation here typical code :

    uuid.randomuuid().tostring() 
  • if want keep track of number of convos, or persist convo ids on server, choice use database such app engine's datastore keep track of variable. if you're new subject, suggest read bit transactions, otherwise not able manage state correctly. note app engine can generate ids automatically you.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -