• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

What is the best way to share an object across multiple applications

Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have three applications that are deployed in Tomcat as three war files. I need to reuse existing code which at the moment manages the logged on user information in a hashTable defined as

The string key is the sessionID and the UserObject is a normal class that has the following methods

The three existing applications have to reuse these user management code which means all three have to use the same instance of the HashTable. I realize that there are better ways of implementing Single Sign services but i am in a position where i have no choice but to reuse existing code/implementation.

I am looking for ways where i can modify the existing applications so that they can access the same instance of the UserManager class which is the class that contains the HashTable. I plan to create a new war file that will contain the UserManager class and other common classes but now the problem is that the servlet spec does not allow acess to data on individual applications i.e. app1 cant access app2's data.

I have been looking around on Google and found that possible solutions.

Solution 1

Add a new application (app4) which the other three applications will use to authenticate the user. The existing war files (app1, app2 and app3) would use app4 for the authentication by using the following approach.

App4 initialises the UserManagerInstance

App1, app2 and app3 would refer to the object as

Solution 2

The other solution is to add the UserManager to a JNDI context and have apps1-3 access it via JNDI.


- Which of the two solutions do you think is better?

- With solution2, how will the UserManager object be initialised before it is put on the ? I am not very familiar with JNDi so would really like to see an example of how i can initialise the object on Tomcat's JNDI and how i can access it.

- The new application will basically be providing a service to the other applications. Is there a better way of providing this service bearing in mind that the framework in use is Struts 1.

Environment used
Tomcat 6
Solaris 9
Struts 1.2


    Bookmark Topic Watch Topic
  • New Topic