cancel
Showing results for 
Search instead for 
Did you mean: 

Why static variables?

Former Member
0 Kudos

Hi all,

I'm a J2EE developer who is a newbie Web Dynpro Java developer fixing some apps done by outside. I am confused by all the static variables. Static variables only have one instance for a JVM. Is there a new JVM for every user's Dynpro app that is started on the portal? Yikes. Otherwise, one user's values would overwrite another user's.

Please set me straight on how static variables work in the Dynpro controller, view, etc.

Thanks,

--Amy Smith

--Haworth

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Where exactly did you find these static variables? I would guess almost all of them (except static final one's) are just plain wrong

Armin

Former Member
0 Kudos

In both cases they are in the "others" section and used throughout the code. One in the controller, the other in a view.

What I am hearing is that no way will these work in production when multiple people are using them!

So, the Dynpro code is executed in a new instance of "the object" that is created by the Web AS portal servlet. So the class variables (member variables,...) will work?

Here is a sample:


  //@@begin others

	//Variables used in the program
	String strPortalUser = "";
	static ConnectionAccessor connection_acc = null;
	static RepositorySchema repository_schema = null;
	static String User_Session = null;
	static FieldProperties[] VT_NumberRange_FieldProperties;
	static TableId VT_NumberRange_TableId;
	static FieldId[] Number_Range_Type_FID = new FieldId[4];
	static RecordId[] VT_NUmber_Protected_By_The_Session = null;
	static String Log_File_Name = "";

	static RecordId Status_Successful_RId = null;
	static RecordId Status_Exhausted_RId = null;
	static RecordId Status_Error_RId = null;

	static TableId MainTable_ID = null;
	static ResultDefinition MainTable_Resultdfn = null;
	static FieldId[] MDM_MainTable_Filter_FId = new FieldId[7];

	static TableId VT_Vendors_TID = null;
	static FieldId VT_Vendors_Name_FId = null;
	
	static  String mdmServerName;
	static  String dbmsName;
	static  String strDBMSType;
	static  String vendorRepositoryName;
	static  String customerRepositoryName;
	static  String repositoryUserName;
	static  String generalRepositoryPassword;
	static  String logFileName = "/usr/sap/SEP/JC01/j2ee/cluster/server0/log/MDMlogs";

I should have known when I saw the capitalized variable and method names.

Thanks,

--Amy Smith

--Haworth

Former Member
0 Kudos

Looks horrible. Replace them by context attributes / nodes and share them between controllers by context mapping.

Armin

Former Member
0 Kudos

Thanks,

By context attributes you mean class instance variables (I.E. just take off the "static")? ...There is only one controller, so there is no need to share variables with another controller.

Thank you very much,

--Amy Smith

Former Member
0 Kudos

I get it. Took a look at node and context "stuff". Thanks. In this case I will just use class attributes as I don't need to share with other components, and I don't really have time to delve into it right now.

Again, Thanks so much. You saved me some headaches.

--Amy

Answers (0)