Re: Impact of having static methods in the helper classes of a Stateless Session Bean
Saturday, October 20, 2001 01:36 PM
no performance degradation will occur with calling static utility classes. however, make sure that those static methods do not operate on the shared data. i.e. if you need those methods to operate on some data, pass that data as parameters to the method. since potentially many EJBs will be invoking this method at the same time, the only way to ensure that data on which it operates is correct is to pass that data to the method. each method invocation contains its own call stack and therefore concurrent calls to static method operate on their own copy of parameters that have been passed in to the method.
in terms of internal memory allocations, it should be obvious that static method is one per class and non-static methods is one per object. therefore, if you have a singleton class, there is the same memory allocation for static and non-static methods. however, if there are multiple objects instantiated for a class, more memory will be allocated for each non-static method of the class. the same applies for static and non-static variables. if a class declares a static char and non-static char, a memory for non-static char will be allocated for each instance of the class and only a single memory allocation will be established for a static char regardless of the number of instances of the class in the VM.