Static variables in servlets
I have a servlet. And in this servlet I have a helper-class that makes all the communications to the backend. Communications to the backend goes through an enterprise bean which is created in the constructor of the helperClass.
What I would like to do is to only run the constructor once for every servlet-request. And after that just access my helperClass in a static way.
So for example
in Servlet-class i write:
and in my other classes i just write:
The enterprise java bean object in the HelperClass is static(lets call in eeObject).
What happens when I do all this is that my eeObject is initialized when accessed for the first time in the constructor. But for every request after that it is never reset. I can even log out and log in with a different user and the eeObject is still the same as when initialized.
So my question is:
How do I get my HelperClass to be unique for every user(or the eeObject). And I would only like to initialize it either once per servlet-request or once per user-session. And at the same time i would also like to be able to access it in a static way.