Dustin Lang wrote:

> Hi,
>
> > Yes, but how do one actually *stop* the application manually, after having
> > denied the System.exit() call? I was playing with the idea to write an echidna
> > type app (as a learning experience), but never got started because I couldn't
> > solve that simple problem :)
>
> Only allow a given thread to stop the application.  A hackish example
> would be this:
>
> System.setSecurityManager(new SecurityManager(){
>         public void checkExit(int status) {
>                 if (!Thread.currentThread().getName().equals("kill
> thread")) throw new SecurityException("naughty naughty.");
>         }
> }
>
> You could also use a special magic status number, such as 0xCAFEBABE :)

It might be worthwhile to register a specific object in the constructor for your
security manager, and save that for later comparison:

class MySecurityManager extends SecurityManager {
 private Thread privileged;
 public MySecurityManager() { privileged = Thread.currentThread(); }
 public void checkExit(int status) {
   if (!Thread.currentThread() == privileged) throw new SecurityException("...");
 }
}

In that example only the thread which created the security manager could shut down
the VM.

Wes



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to