Skip to Content

Adressing an object via JNDI in SAP Netweaver AS Java with Multiple Nodes

Nov 02, 2017 at 09:12 AM


avatar image


I am trying to create a simple cache for some values in Netweaver AS Java. For that purpose I created a session bean which is accessible via web service and has two simple operations storeValue(String key, String value) and getValue(String key).

My first idea was to create a singleton object that holds the values. That fails because singletons apprently exist one time per node. Another idea was to create a serializable object and bind it in the JNDI context. Binding the object is not a problem, I can see it in the JNDI browser. But retrieving the object in my session bean is sometimes successful and sometimes it fails. It seems that it also depends on the node on which my session bean is executed.

I found this thread regarding the same topic but no answer:

In the constructor of my session bean I have the following code:

Context ctx = null;

try {

ctx = new InitialContext();

Map<String, String> cacheValues = (Map) ctx.lookup("CacheValues");

location.infoT("LookupResult of 'CacheValues' " + cacheValues);

if (ctx != null && cacheValues == null) {

cacheValues = new HashMap<String, String>();

ctx.bind("CacheValues", cacheValues);

location.infoT("Bound new object to JNDI context");


} catch (Exception e) {

location.errorT("Unable to retrieve 'CacheValues'");


* Is there anything wrong with my code?
* Are there distinct JNDI contexts per server node?

Any hint is appreciated.


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Richard Zhao
Nov 30, 2017 at 08:09 AM

Hello, Stefan. According to your description, Apparently the bindings are not be replicated across the JNDI tree of each server process within the cluster, That could be the root cause of your issue.

If you need bindings to be replicated across the JNDI tree of each server process within the cluster, it has to use instead of . when you create initialContext

Context ctx = new InitialContext();

If you want to get more information about NW JNDI. You can refer the link below.

10 |10000 characters needed characters left characters exceeded