i am working on a GWT web application and i was wondering if there is a way to keep some classes alive on the server.
The point is that i would like to create a static class that will run on the server and manage something for me.. lets say currently logged in users.
public class someclass{
private static someclass instance;
private List<user> users;
private someclass(){
users = new ArrayList<user>();
}
public someclass getInstance()
{
if (instance == null)
instance = new someclass();
return instance;
}
public addUser(user u)
{
users.add(user);
}
}
assume that there is no sync needed its not impotent for the question.
lets say first user logs in, and is added to the users list.
when a second user logs in. will the user list be empty? or will it have the old user as well?
Thanks…
There are different ways to do this. However, a very simple way to tackle this scenario would be to use a startup servlet
In web.xml define it as follows.
Maintain the stat in static fields of that servlet.