Why in EJB static variables are discouraged?
Regards,
aakash
-
EJB static variables (1 messages)
- Posted by: aakash bhatt
- Posted on: September 01 2003 10:49 EDT
Threaded Messages (1)
- EJB static variables by Gal Binyamini on September 01 2003 14:37 EDT
-
EJB static variables[ Go to top ]
- Posted by: Gal Binyamini
- Posted on: September 01 2003 14:37 EDT
- in response to aakash bhatt
I'm not sure I would say static variables are "discouraged". They are somehwat problematic because the behavior of EJB code that uses static variables may change from container to container based on the class loading strategy each container uses and the number of computers the application is deployed on.
That doesn't mean you can't rely on static variables if you know what you're doing. Sometimes static variables in EJB are useful, but you have to design your application so that the basic behavior doesn't change if two pieces of code see the same static variable or seperate static variables. For instance using a static variable as a global counter is no good. Using it to hold something like a Preferences object is usually ok, because there is no harm in loading multiple instances of this object in the case that each component sees a different variable. As a rule of thumb, you can use static variables to improve performance but you can't rely on them to implement your basic business logic.
Gal