I am working on storing different user counters in memory at application level (not database) and to have counters to atmost 3.

I developed this code using a singleton class with hashmap to store a key value pair of user id and and it's counter and time.

After initial, i was using this singleton class on client side, it worked fine for counters but when browser was refreshed, a new singleton object was created.

I searched, and come to know that for security reason, javascript don't use shared objects, so i moved it to rpc call and make it server side object to overcome it, but when i tested it again, on refresh new object is created and data lost.

I also tested the static hashmap to hold the data for application scope, but it has almost the same behavior, once refreshed the browser, its reset and old data is lost in it. It little different behavior from normal java web apps where we follow this approach.

this technique used to work for me in case of normal spripng web applicatoins, but not in gwt

有帮助吗?

解决方案

You are correct, you'll need to store this value on the server-side and access it via an Async call. Since you have had success with Spring in the past, you might consider using it again with the implementation side of your GWT Async services. You can easily inject a Spring Singleton bean into the GWT Async implementation class and use it like you have in the past.

其他提示

What's the expected life of the counters? Are they shared by other users? You can store them in the DataBase or in a Session and access them through a GWT Async call.

You can use GWT HTML5 LocalStorage to have client-side persistent data or of course use the server-side. It really depends on what you are trying to achieve.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top