Results 1 to 2 of 2
Thread: Static variables in servlets
- 09-26-2010, 11:55 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 1
- Rep Power
- 0
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:
new HelperClass();
and in my other classes i just write:
HelperClass.getDataA()
HelperClass.getDataB()
etc etc.
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.
Thanks
- 09-26-2010, 12:41 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
can we synchronise static variables
By sandeepsai39 in forum New To JavaReplies: 4Last Post: 09-02-2010, 01:25 PM -
Still having trouble with static & non-static variables
By Psyclone in forum AWT / SwingReplies: 6Last Post: 02-15-2010, 04:31 AM -
What are Instance variables and static variables?
By sandeshforu in forum New To JavaReplies: 3Last Post: 09-09-2009, 05:48 PM -
Using Static Variables
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 11:08 PM -
Help with static variables
By bbq in forum Advanced JavaReplies: 1Last Post: 06-28-2007, 05:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks