Q:

Infinite Loop and System.exit(0) in java

I was wondering if it was bad coding practice and/or some consequences if I make an infinite loop(i am checking if a program has started) and when a condition Im checking becomes true, I use system.exit.

A:

An active wait loop is usually a terrible idea. It makes the entire machine slower (including start-up of the other program). Find a way to just listen for a program start event. Without any details of your code, I can't provide any more specific suggestions.
There's nothing inherently wrong with calling System.exit(0); it all depends on what kind of program it is. (E.g., a Swing application should just set DISPOSE_ON_CLOSE or EXIT_ON_CLOSE for the application's JFrame and then close the frame.)

A:

You may be better off using the java.util.Timer and java.util.TimerTask classes, and recursively relaunching the timer as it expires. As the above post says there is nothing inherently wrong with using System.exit.
public static void main(String[] args){
    Timer timer = new Timer(); //create a new timer
    timer.schedule(new TaskLoop(), 1000); //schedule the task for 1000ms (1 sec)
}
class TaskLoop extends TimerTask {
    public void run() {
        System.out.println("here"); //timer's up, do whatever you need to do
        Timer timer = new Timer();
        timer.schedule(new TaskLoop(), 1000); //start another timer.
    }
}

