• Post Reply Bookmark Topic Watch Topic
  • New Topic

Easiest way to combine 2 different java applications  RSS feed

 
Kashyap Hosdurga
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am back to Javaranch after a looooong time. We have 2 different applications that we are developing (Java and JSF). Now business has a new requirement that the 2 applications should be running together and if one of them is not running then the other one should not run (can shut down automatically). We have completed the development under the previous assumption that these 2 applications will be running separate. Now with the deadline very close we are looking for some "hacks" to make sure both the applications are either ON or OFF. One of my team members suggested that we can have them in a single JVM (with minimal modification to code) that way if the JVM is down then both the applications will be down. Please suggest any better ways of achieving this.

Thanks,
Kashyap
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say Java, do you mean a standalone Java app? Or a Servlet app? And I presume they are running on the same machine?

How long does the second one have to shut down when the other is shut down? Five minutes? Five seconds?

How are both applications turned on and off now?

The answer to these questions will influence recommendations.
 
Kashyap Hosdurga
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne for your quick response.

1. When I say Java yes I mean servlet (sorry I was in a hurry while typing) and yes they will be running on the same machine
2. When the first one shuts down the second one has to shutdown within the minute (60 secs)
3. The applications are not turned off or on, they will be running as separate JVMs (as planned originally)

The new requirement is to have the dependency that both applications are either up or down.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification. I can think of two approaches. One is the merge you suggested.
1) If the two apps are using different versions of an open source jar, one will have to change.
2) If the two apps use any code in common that uses statics/caching, that would get intermingled.

Both of these scenarios require a good bit of testing so make sure you can accommodate it. I do think it is a good idea to merge them as they sound like on app. Or to put the two wars int he same ear so they can be started together if you are on an application server. (They are in different JVMs that way)

If I needed a shorter term hack, I'd write something like this:
1) On servlet startup write to a file on disk the start up time of each app.
2) Have a timer in both apps that updates this file every 30 seconds with the current time.
3) If that timer sees that the other didn't update in the last 50 seconds, set an "inactive" status and display an error message instead of letting the user in the app
4) If the timer is on the "inactive" app and sees the other did update recently, go back into "active" mode.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a bit difficult to respond as you don't clearly state what "down" means - web app responding, but turned off somehow? web app up, but not responding? web app down, but JVM up? JVM down?

As a short term solution I'd probably go with something like Jeanne suggested, but not based on files (don't like to use them for synchronization purposes, too many things can go wrong), but based on HTTP calls. Each app calls into the other every X seconds, and then the other app can take action if the calls have been missing for Y seconds. Accepting HTTP calls should be easy, given that these are web apps.
 
Kashyap Hosdurga
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per business, they want both the application to be running.

1. Since both the application and JVM are on the same server, if the server is down then we don't have any issue
2. If server is up but
2.1 One of the the JVMs is down
2.2. The application is not responding for some reason
then we don't want the other application to be up (we have to display a "Sorry, please try after sometime " page)

So we figured only when the JVMs are together then we can fix one of the issues (2.1). Now we have to make some more changes if the application is not responding (at a later time with additional effort)

Thanks,
Kashyap
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,
I like the HTTP call idea!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each app calls into the other every X seconds,



Really only one app needs to do the calling, the other can remember the timestamp from when it was last called.


Bill
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a load balancer in front of the application, won't it be easier to switch the load balancer to point to a "dummy" site that says "down for maintanence. Please check after some time".
 
Kashyap Hosdurga
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,
Thanks for the simple yet brilliant idea of HTTP call.

Jayesh,
We do have a load balancer, but the point is to have both the apps be available and if one of them is down (for any reason pointed by Ulf) the other app also should not be up and running.
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kashyap Hosdurga wrote:
Jayesh,
We do have a load balancer, but the point is to have both the apps be available and if one of them is down (for any reason pointed by Ulf) the other app also should not be up and running.


yes. I understand that. you should be able to put something on the load balancer that takes both applications offline when one of them goes down. Applications pinging each other might sound like a simple solution, but will have complications when you actually do it

1)what will be your test environment? You can;t test each application independently? Seems kind of silly to force both apps to be up
2) How do you bring both of them up together?. You don;t want one to come up detect that the other is not up and shut itself down, right? Do they start checking 2 minutes after they come up? Or do you have some sort of mechanism for one app to tell the other app:- "Oh I'm coming up.. check again in few minutes"
3) How do you scale this up? DO all servers ping all other servers?

It seems to me that the load balancer is a perfect place to make a decision like this. If you are using Apache Server, you could have an application that monitors the log and when it sees an error, it can change the rules to point both application to an error page. Really, if you know Linux scripting, you can do this in couple of lines of script
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!