Hi,

posted from Java developer connection (sorry I didn't fix indentation). The
code works. I tried it, but I created a watch thread instead of using the
main thread.

from http://forum2.java.sun.com/forum?14@@.ee7b71f

===================================== excerpt start here ====
 code NOT tested. but it should not be far from a solution for fasay's
problem.
import sun.misc.*;

/* * this main makes something and catch Ctrl-C in order to * clean its work
env before to leave. */ public void main(String args[])


final Thread theMainThread = Thread.currentThread(); SignalHandler
theOldSignalHandler = null;

// makes a signal holder which will interrupt the main thread // if Ctrl-C
is typed try { theOldSignalHandler = Signal.handle( new Signal("INT"), new
SignalHandler() { public void handle(Signal sig)
 theMainThread.interrupt(); } } ); } catch (IllegalArgumentException exc) {}

// makes a unused object in the main thread, // sleep on it until wait()
raise InterruptedException // (raised if ctrl-C is typed) Object sync = new
Object(); synchronized(sync) { try { sync.wait(); } catch
(InterruptedException exc) { // write here the code used to clean what you
want server.shutdown(); // and exit cleanly System.exit(0); } } }
======================================excerpt ends here==========

----- Original Message -----
From: "Chris Kelly" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, March 30, 2000 11:31 AM
Subject: Re: HELP: using unix-signals?


> http://interstice.com/~kevinh/projects/javasignals/
> http://www.naturalbridge.com/useful/index.html
>
> At 07:06 PM 3/30/00 +0200, Bruno Boettcher wrote:
> >i didn't found this in the FAQ's nor in the docu.... is there a way to
> capture
> ><ctrl>-c interruptions or as long as this one to any one of the other
> >unix-signals?
>
>
>
>
> oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo
>                          Send Sun a Message!
>           Vote for JConfig in the JDJ Readers' Choice Awards.
>             http://www.sys-con.com/java/readerschoice2000/
>                  See the 'Best Class Library' category.
> oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo0oo
>
>
>
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
>


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

Reply via email to