2

I have very strange problem- from one program I run another application- by Runtime.getRuntime().exec(). It's look like something like this:

Runtime.getRuntime().exec(java -jar Something.jar + "bla bla params");

And when I run this code from new project- everything is ok. But if I run this app from our system in company- the smaller application occasionally hangs. And there is even better- if I close "parent" program, application "return to live"! The app (which hangs) is small java swing application. The big application is java swing app too. It uses the same db connection as application which run small app (Something.jar). Maybe that cause problem?

But for me it have no sense- if I run app by Runtime.getRuntime().exec- the running app is separate application container in separate JVM! How test/debug that configuration?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Nicramus
  • 606
  • 1
  • 6
  • 19
  • 6
    Do you consume the stdout and stderr streams of the process? See also: http://stackoverflow.com/questions/3285408/java-processbuilder-resultant-process-hangs – assylias Jun 30 '15 at 11:37
  • @assylias No, I don't. Good point. – Nicramus Jun 30 '15 at 11:39
  • 1
    [see more inspiration for testing purposes and real options rather than using Runtime.getRuntime](http://stackoverflow.com/q/6121990/714968) – mKorbel Jun 30 '15 at 13:06
  • 1
    See also [When Runtime.exec() won't](http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html) for many good tips on creating and handling a process correctly. Then ignore it refers to `exec` and use a `ProcessBuilder` to create the process. – Andrew Thompson Jun 30 '15 at 15:14
  • 1
    `Runtime.getRuntime().exec(java -jar..` This is not the easiest or best way to run another Java app. I would establish an `URLCLassLoader` pointing to the Jar, then call the `main(String[])` method (or even the constructors, if you know the code base) and launch the 'other app' from the same Java Virtual Machine. This gives the programmer a more robust way to interact with the new Java program, and easy ways to manage the input and output. – Andrew Thompson Jun 30 '15 at 15:17

0 Answers0