From: Todd on
Hello,

I have a Java process that when it is improperly configured, it needs
to halt (programmatically). My understanding was that
System.exit(status) was the way to do this. There has been some
grumbling that there may be another, better way to do this, but nobody
has an specifics. References have been made to Eclipse and JBoss, but
Google hasn't turned up any useful results.

Anybody here know anything about this? I know it is a bit ambiguous,
but I am searching the darkness with a penlight for answers to this.

Thanks,
Todd
From: Alessio Stalla on
On Jun 10, 4:52 pm, Todd <todd.heident...(a)gmail.com> wrote:
> Hello,
>
> I have a Java process that when it is improperly configured, it needs
> to halt (programmatically).  My understanding was that
> System.exit(status) was the way to do this.

It still is.

> There has been some
> grumbling that there may be another, better way to do this, but nobody
> has an specifics.  References have been made to Eclipse and JBoss, but
> Google hasn't turned up any useful results.

Neither Eclipse nor JBoss are likely to have anything to do with
exiting an application.

Just keep in mind that System.exit kills the entire JVM, so if your
"process" is a webapp in a servlet container, you'll kill all the
other webapps and the container, too.

Regards,
Alessio
From: Todd on
On Jun 10, 9:06 am, Alessio Stalla <alessiosta...(a)gmail.com> wrote:

> Just keep in mind that System.exit kills the entire JVM, so if your
> "process" is a webapp in a servlet container, you'll kill all the
> other webapps and the container, too.
>

That's what I understood, but thanks for the reminder. For the
purposes of this process/application, failing to a safe-mode (in this
case where no further processing is allowed) is best, so halting the
JVM is reasonable.

Todd
From: Todd on
On Jun 10, 9:15 am, r...(a)zedat.fu-berlin.de (Stefan Ram) wrote:
> Todd <todd.heident...(a)gmail.com> writes:
> >I have a Java process that when it is improperly configured, it needs
> >to halt (programmatically).  My understanding was that
> >System.exit(status) was the way to do this.  There has been some
> >grumbling that there may be another, better way to do this, but nobody
> >has an specifics.
>
>   I prefer, in a console application, to return from »main«,
>   and in a Swing application, to dispose all Swing resources.

This process is running in the background as a Windows service. In
the most likely scenario, the interface will have not yet
initialized. In the least likely scenario, there will be an interface
running in a browser, attempting to connect with this server process.
The server process failing to a safe state (not accepting further
input, halting processing - in this case) is expected.

With that in mind, since the use case presents abnormal situations,
what is your preferred exit strategy?
From: Eric Sosman on
On 6/10/2010 12:02 PM, Todd wrote:
> On Jun 10, 9:06 am, Alessio Stalla<alessiosta...(a)gmail.com> wrote:
>
>> Just keep in mind that System.exit kills the entire JVM, so if your
>> "process" is a webapp in a servlet container, you'll kill all the
>> other webapps and the container, too.
>>
>
> That's what I understood, but thanks for the reminder. For the
> purposes of this process/application, failing to a safe-mode (in this
> case where no further processing is allowed) is best, so halting the
> JVM is reasonable.

Keep in mind that things like application servers and browsers
will not allow applets/servlets/whatnot to stop the JVM: They'll
install security managers, and System.exit() will wind up throwing
SecurityException. Assuming you don't catch it, this will cause the
thread that called System.exit() to terminate. But if you've launched
additional threads, they won't be affected by the intercepted attempt
to exit. Not necessarily a problem (especially in your case, where
I gather the problem is detected early and you might not have launched
a lot of threads yet), but something to be aware of.

--
Eric Sosman
esosman(a)ieee-dot-org.invalid