unix - What is the best way to keep a Java program running forever, or for a very long time? -


i have java app supports multiple workflows. workflow chosen using arguments passed command line. in 1 of workflow app needs run infinite time. achieving same using following code

switch (args[0]) {      case "-runforever":      // computation      thread.sleep(long.max_value);      break;     case "othercase:      //dosomething      break; } 

is way of achieving required functionality?

you use infinite loop:

while(true){} 

however, eat cpu no reason. instead, call wait() method:

synchronized{    wait(); } 

then resume, you'd call notify() thread.

more info here.

you start non-daemon thread.


Comments