3

I have an eclipse project regrouping two applications, I want to run the second application by itself or from the first one, which I managed to do by simply calling the main method. The problem is that when I start that second app from the first, when I close that second application it also close the first application. Can I avoid that behavior and keep the first application running?

Thanks.

Jkmn
  • 571
  • 5
  • 11
  • 2
    Sounds like the second application is calling `System.exit()` at some point, causing the whole process to end. Hard to give advice without more concrete data... – Ariel Apr 18 '12 at 03:15
  • *"The problem is that when I start that second app.. when I close that second application it also close the first application."* See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Apr 18 '12 at 04:05

1 Answers1

4

Your second application is probably issuing a System.exit when closing. The only way of preventing this from dragging down the invoking application is to start it off in a separate process (via ProcessBuilder.start or Runtime.exec for instance), or by trapping and preventing the System.exit via means of a custom security manager.

Perception
  • 79,279
  • 19
  • 185
  • 195
  • Hey @AndrewThompson - I assume he doesn't control the code or he wouldnt be asking this question. But you never know. As for the NoExitSecurityManager, that is what I mean by custom security manager, in my answer above. – Perception Apr 18 '12 at 04:11
  • My bad. I misread both the question **&** your answer. (Gotta' have my coffee..) – Andrew Thompson Apr 18 '12 at 04:16
  • I do control the code, but if I don't exit, that second application process won't terminate when it is run by itself. – Jkmn Apr 18 '12 at 05:32
  • Without seeing some of your code its hard to say what the difficulty is in managing the lifecycle of both apps, especially if they are both under your control. One thing you might try doing is too open the second application via a call to main, when in standalone mode, but to open it via a managed method when in 'embedded' mode. In standalone you allow the close app function to do a system.exit, but in the embedded mode you dont. – Perception Apr 18 '12 at 05:46
  • Thank you, I used the String[] args to know whether or not I execute this.setDefaultCloseOperation(EXIT_ON_CLOSE); instruction. – Jkmn Apr 18 '12 at 06:03