Reputation: 1452
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?
Upvotes: 2
Views: 3949
Reputation: 47183
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.
Upvotes: 1
Reputation: 4829
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);
Upvotes: 1
Reputation: 709
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.
Upvotes: 1