2

Is there in Java any command or proccedure that I can restart my appliation itself?

I developed a Java desktop application, but after some time it's going hang. I don't know why, so I want to restart my application itself. Is it possible?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ravi Parmar
  • 1,392
  • 5
  • 24
  • 46
  • How would a application which hangs do anything? Also you should use a debugger to find out why it hangs. – josefx Oct 30 '10 at 14:39
  • this is a duplicate of http://stackoverflow.com/questions/3854997/how-to-restart-java-application-remembering-its-command-line-arguments. The accepted answer is the way to go. – barjak Oct 30 '10 at 20:40
  • This is why software sucks these days. Sorry. – Jonathon Reinhart Jan 07 '12 at 03:59

3 Answers3

1

It should be possible by using Runtime.getRuntime().exec(command);, but I think the better solution here would be to find the reason why your application hangs after a while. Just because your application starts to hang after, for example, two hours doesn't mean that it didn't already ill behave a long time before.

bjoern.bauer
  • 699
  • 3
  • 6
1

I would recommend to try hard and fix the problem that causes your app hang. But if you still want to restart it I think the only way is running a new instance and killing the old one:

RunTime.getRuntime().exec("java My_Program");
System.exit(0);
Miquel
  • 4,741
  • 3
  • 20
  • 19
1

You're doing it wrong. Find out why your application hangs by debugging it or adding some logging code, and after further examination fix the problem.

My answer is a bit general, but to make an analogy; you're trying to open the front door of your house using a sledgehammer without checking your pockets first.

darioo
  • 46,442
  • 10
  • 75
  • 103