2

I have two projects, project1 and project2.

Case 1: Project1 and Project2 are on the same machine. If project2 crashes or terminates, Project1 should restart the project2.

Case 2: Project1 and Project2 are on different machine. If project2 crashes or terminates, Project1 should restart the project2.

These are java project.

How should I perform the aforementioned task?

EDIT:

I was thinking of the following solutions:

  1. If the projects are on the same machine then I can keep the Project2 in the classpath of Project1 and restart the project2 from project1. But, there is a problem. Then these two entities will become a single program.
  2. If these projects are on different computers then I could have some third program running along with project2 which I will assume will never crash. And this third program could revive the project2.

Not sure, about my solution. Your input is required.

John Rambo
  • 906
  • 1
  • 17
  • 37

2 Answers2

2

We use RabbitMQ: The Project1 send requests about task using RabbitMQ and Project2 send notifications about his job unsing RabbitMQ. If Project2 didn't send notification during some time (for example, during 30 seconds) Project1 start new Project2 instance just using OS command or send requests Project3 that in some machine like Project1 and using only for starting Project1 instances using OS command.

Of course, you can use any message brokers, not only RabbitMQ.

But, there is a problem. Then these two entities will become a single program.

No, mush better start all project as separate programs, if the Project2 has Out Of Memory error or so on, the Project1 also died. It isn't a problem at all runing Java application using ProcessBuilder or so on.

Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
  • Thanks!! But it is a distributed system assignment and we are suppose to use distributed algorithms, that's why I am not sure whether I can use RabbitMQ for this. – John Rambo Dec 02 '15 at 17:47
  • You could use any JMS query or just remote or local files to save heatbeat of Project1. Or the Project1 can provide small webservice, that just returns "All ok! I'm working!" – Slava Vedenin Dec 02 '15 at 17:49
  • Yeah, I am using heartbeat/ping technique for failure detection. However, I am stuck at the recovery part. – John Rambo Dec 02 '15 at 17:52
  • The recovery part is the easiest part, just run application of Project2 using Os command (of course, in Project1 and Project2 be run on different machines, you need Project3 that just running Project2 in same machines. – Slava Vedenin Dec 02 '15 at 17:55
  • Okay, thanks!! One more question, I have to use processbuilder, that will use os command to revive the project2, right? – John Rambo Dec 02 '15 at 17:59
  • Right, just call "run.sh" , "run.bat" or "java -jar ..." of your Java application using processbuilder – Slava Vedenin Dec 02 '15 at 18:03
  • Thanks for your time!! – John Rambo Dec 02 '15 at 18:13
1

Case 1: one app can start another: ProcessBuilder

Executing another application from Java

Case 2: quasi-impossible as asked. You need something running in the machine of project 2.

Community
  • 1
  • 1