cancel
Showing results for 
Search instead for 
Did you mean: 

Private static fields in controllers

Former Member
0 Kudos

Hi, all!

Could anybody tell me how private static variables declared between @@begin others and @@end others are being accessed?

What I mean is: Are they - as class variables - unique within memory and their values therefore not threadsafe or are they unique for each thread?

Thx!

Regards,

Thomas

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thomas,

Theay are just regular java static class fields.

So:

1. public static String KEY = "SOME_VALUE";

-- mutable non-thread safe static class variable

2. final public static String RO_KEY = "SOME_VALUE";

-- immutable (hence thread-safe) static class variable;

3. final public static ThreadLocal THREAD_KEY = new ThreadLocal();

-- static class variable with per-thread content

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Thomas,

First of all use of Static variables in WD is not encouraged. As far as possible we should use context only.

Coming to your question the static variables are class variables and these are like normal class static variables of a class and behave like them only.

Thanks and regards

RK

Former Member
0 Kudos

<i>First of all use of Static variables in WD is not encouraged</i>

Yes, if they are used as well-known anti-pattern for sharing data between action / event handler and wdDoModifyView.

More interesting question, that deserves its own place in WD quizes: why using of ThreadLocal in WebDynpro (or any other J2EE container like Web or EJB) could lead to errors / inconsistencies?

Thoughts?

VS

Former Member
0 Kudos

<i>More interesting question, that deserves its own place in WD quizes: why using of ThreadLocal in WebDynpro (or any other J2EE container like Web or EJB) could lead to errors / inconsistencies?</i>

because of thread pool

... just as answer to quize ))