wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Sharing objects across a Tomcat cluster Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Sharing objects across a Tomcat cluster" Watch "Sharing objects across a Tomcat cluster" New topic
Author

Sharing objects across a Tomcat cluster

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Is there an object that is shared across clustered tomcats that can take attributes and paramaters?

Like an 'application' object. I can add an object to it on one node and pick up that object on another node?

Basically I am looking for a simple solution to sharing data across nodes rather than implementing oscache and jgroups. I am sure I read about something like this years ago but cannot find it now, it may have been depricated.

Thanks



David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
I think I have it..


ServletContext

I will see if changes reflect across the cluster now.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Sadly changes to the ServletContext are not dealt with over the cluster.

I thought they would work the same way as the session when you change attributes.

Maybe this is something they should look at changing, i cannot see why each application in a cluster needs to have seperate contexts.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

Hi David,

I'm not an expert in clustering Tomcat but I'm pretty sure Tomcat doesn't replicate objects across a cluster automatically. This isn't even guaranteed for the said session attributes as far as I know. They are replicated to another Tomcat node in your cluster if a client connects to this other node and there is an established session already available (of course Tomcat has to be configured then to actually do session replicating). But I think this mechanism is not meant to make some objects visible to all nodes in a cluster at once.

Why don't you choose the typical solution and use some kind of centralized data store like a database system? I guess you will already have some kind of database in a clustered environment. Isn't this an option for managing shared data?

Another more or less easy to use solution I can think of without using a distributed cache or something like this would be to use Terracotta. Terracotta is able to cluster JVMs across multiple servers and simply make them available to applications as if it was only one JVM. The current version explicitly supports running Tomcat 6 on such a Terracotta cluster. Because for Tomcat and your web application this would seem like running on only one physical server node, attributes you put into the application context would be globally available in your application. Unfortunately I've never used Terracotta for clustering Tomcat myself, so I can't promise you that this approach definitely works but from the documentation and other things I read about this it should be possible.

Marco
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Thanks for the reply Marco,

I am going to look at running tomcat under Terracotta, never though about that approach, thanks.

The app is going to be running under the amazon cloud and it is designed to change the amount of servers automatically as the demand rises and falls. I have tested the sessions and they seem to be able to deal with that quite happily.

One server is going to be running a batch job and I wanted to store it's results in the ServletContext to be shared with the other servers and although the docs say Context Attribute Replication is possible it just won't work.

If Terracotta can deal with servers coming on and off and will truly act like the one node then that could solve a few problems in one go.

Going to look at the docs now. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sharing objects across a Tomcat cluster
 
Similar Threads
sharing attributes/datas between servlets
How to specify application configuration file
Problem with jsf tree
tree interface
Linked List Help