Discussions

General J2EE: EJB static variables

  1. EJB static variables (1 messages)

    Why in EJB static variables are discouraged?

    Regards,
    aakash

    Threaded Messages (1)

  2. EJB static variables[ Go to top ]

    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