on 10-17-2007 6:33 PM
Hi,
I have a question regarding static java classes in WebDynpro: Does anybody know details about their lifetime. I was searching for this information but I didn't find info.
The background of this question is, that I would like to store configuration data (customizing) from the R/3 in a static class of my WebDynpro application, in order to minimize DB requests. Exists a static class for the whole WebDynpro session or is it destroyed after every user interaction?
Thanks in advance,
Martin
Hi Martin,
static variables and classes should be used with care - I've just seen a serious problem because a static variable lived longer than expected. After a class containing a static variable has been initialized it remains inside the VM until the J2EE engine has been restarted. In other words, the static variable keeps its value even after a new invocation of the WD Java application. This can lead to unpredicted behaviour if not considered. I'm not sure how multiple users are handled, e.g. if every user gets his own VM space, which I would expect.
For what you're trying to do I wouldn't use a static class, but favour the solution suggested by Surya, with an additional refresh whenever the customizing data may have changed (depending on your scenario). However, note that this only stores the data for the lifetime of the component controller, unless you map the context to other components as well.
Hope this helps,
regards
Thomas
PS: To add to Abhijith's post, a class is called static whenever it has at least one static class variable, but you can of course not use the "static" modifier in the class declaration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
If I have understood you
You want to create a static class, you are expecting the values will remain same for the lifetime of the
webdynpro app.
In order to understand the use of the static keyword in class declaration, we need to understand the class
declaration itself. You can declare two kinds of classes: top-level classes and inner classes.
Top-level classes
You declare a top-level class at the top level as a member of a package. Each top-level class corresponds to
its own java file sporting the same name as the class name.
A top-level class is by definition already top-level, so there is no point in declaring it static; it is an error to do
so. The compiler will detect and report this error.
you cant write a code like
public static class hello {
}
it gives an error like
Illegal modifier for the class hello; only public, abstract & final are permitted
........................................................................................................................
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Martin,
My advice is get the configuration data in the WdDoInit method of the View and store it in component controller's context which would stay there for the whole life the WD component. For this create a same context structure in component controller and map it from the view controller. Please let me know if this works for you.
P.S : I guess the lifetime of any method in the View controller expires as soon as another view is loaded in its place.
Thanks!
Surya.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.