This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

many applets accessing a writing servlet ...

 
Maurice Huellein
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a game - applet which includs a highscore. to save the scores permanently theres also a servlet for accessing the server resources. so if theres a new highscore reached the applet sends it to ther servlet, which writes the score in a txt-file on the server.
but im smelling problems if several applets are running at the same time:
for each applet instance a unique servlet connection is created for highscore entry. so only **** would happen if one connection writes to the file, another one reads at the same time and so on.

how can i safely synchronize the data ?

btw: for this project i have no access to a database (which would make many problems obsolete ...)
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could synchronize access to the method that saves the high score and keep a copy of the current high score in memory.
Bill
 
Maurice Huellein
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to clear some points on your suggestion:

as far as i know every applet which starts an urlconnection results in a new instance of the servlet. so i have to care about more than one servlet instance. to have a shared copy of the highscore in memory i would declare it only as static and declare the methods which access the highscore as synchronized...

did i get the point right ?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as far as i know every applet which starts an urlconnection results in a new instance of the servlet.

I think you better get servlet basics firmly in mind before embarking on a project because this is exactly wrong. The Sun tutorial would be a good place to start.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic