How is it possible to stop part of the system and leave the user interface still running?

Go To StackoverFlow.com

1

I am building a system where there is a simple GUI which will trigger the system to execute. I implemented the system in a way that when an exception is thrown, System.exit(0) is called and so the application stops.

I would like the implementation to stop, as it is doing now, however I wish that the GUI would not be closed as well. I tried implementing the system in a separate thread, however when some exception was thrown, the application still closed down.

Is there a way to leave the UI open, but still stop the implementation?

2012-04-05 21:26
by ict1991
See also <code>Launcher</code> - trashgod 2012-04-05 21:37
Would the down-voter care to share their reason? IMWTK - Andrew Thompson 2012-04-05 21:40
Upvoted: It's a simple mistake that someone who did not understand the JVM would make.. - Michael 2012-04-06 01:10


2

You cannot use Java system.exit for that purpose because that function kills the instance of Java Virtual Machine that is running your code, consequently stopping all the threads of your application.

In order for System.exit to work the way you want it to right now, you would need to have two different processes, so that each of them would run in its own Java Virtual Machine. However, this will make it harder to link things together.

Ideally, you should add some sort of control in the implementation, so that your GUI thread could activate or deactivate a switch which would naturally stop the logic of the implementation. This really is the best way to go in my opinion.

2012-04-05 21:32
by Luis Miguel Serrano


0

Essentially, they will need to be separate applications. That is, make them separate processes, not separate threads.

This kind of loose-coupling between your UI and back-end will achieve the behaviour you want, and also yields a bunch of other benefits relating to separating the concerns of your UI and your backend.

2012-04-05 21:29
by Oleksi


0

No, there is no way to keep your UI open if your program is running on the same process. I suppose you could run your UI and your program as separate applications, but that seems tedious and error prone. If an exception is thrown, you should be notifying the user, not just exiting the JVM.

2012-04-05 21:31
by Jeffrey
Ads