Search code examples
javadetectionrecovery

How to start one program from another program


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.


Solution

  • 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.