0

I am creating a web application. Same application will run from different machine, but they will use common database. When application starts it will get all data from database. But when I update data from one application, how other running application will know that data has been updated, I want when I update database form any application, other running application will get notification immediately, and they should update their data.

One possible solution is I can take all applications URL in a list, then after updating value I will send request to all application, but how to do this using send Redirect. Is it correct way ? or is their any other easiest way to do this. Please help me.

Rocky
  • 161
  • 1
  • 1
  • 12
  • What is the architecture of your web app? Especially, its database layer. Is it plain `JDBC`? – PM 77-1 Dec 30 '13 at 17:35
  • I am using JPA, I will update data rarely like once in a month. I have created a servlet which will update its data, but the problem is how will I invoke this servlet outside of the application, I have a list of all applications URL. – Rocky Dec 30 '13 at 17:43
  • Do **all** of your applications use `JPA`? – PM 77-1 Dec 30 '13 at 17:49
  • yes, this is same application, Only it will run from 5 or 6 machine in tomcat. – Rocky Dec 30 '13 at 17:54
  • Have a look at http://en.wikibooks.org/wiki/Java_Persistence/Persisting#Refresh and http://en.wikibooks.org/wiki/Java_Persistence/Caching#JPA_2.0_Cache_APIs – PM 77-1 Dec 30 '13 at 18:09

1 Answers1

0

Is it a requirement that data is loaded once on startup? If it's not than you can just read directly from the database with a low cache invalidation time.

In case your apps need to be synchronized "almost immediately" I would do it like this:

You can set up a messaging server which would create a JMS topic. All of the clients will listen to messages from that topic. When one of the apps update something in the DB it will send a message to the topic. The rest of the apps will get the message and update.

dimoniy
  • 5,820
  • 2
  • 24
  • 22
  • Thanks @Dmoniy, I will try this. but I will update data rarely like once in a month, will messaging service slow down my app ? – Rocky Dec 30 '13 at 17:45
  • @RockyMajumdar - If your requirements are not real-time and you use full-blown app server (like `GlassFish`) you can set-up your update servlet to run at predetermined times (using timing service). – PM 77-1 Dec 30 '13 at 17:52
  • @RockyMajumdar it will not slow down the app, but it may slow down your server a little bit. Messaging server is usually a separate application which consumes some memory. There shouldn't be much CPU usage because you'll not be using the server often. – dimoniy Dec 30 '13 at 18:06