[Fwd: Re: (Review ID: 100683) Runtime.addShutdownHook doesn't work...]

Hi !

----

Yves, Benoit - can you verify the followinng info, please ?
If this works we have a working way to get rid of the "user hit
^C"-problem...

BTW: JDK1.3 implements also a way to launch a external program WITH
supplying the current working directory...

-------- Original Message --------
From: sandeepk <sandeep.konchady@eng.sun.com>
Subject: Re: (Review ID: 100683) Runtime.addShutdownHook doesn't work...
To: Roland.Mainz@informatik.med.uni-giessen.de

Hi Roland,

Thank you for using the "Report A Bug" feature. The bug you have
reported was tested on Sun4 Solaris 2.7 and Windows NT 4.0 SP4.
Under Solaris I used the proposed release of JDK 1.3RC1 and under
JDK 1.3RC1 release that is available from JDC. Under both these
platforms and JDK revs the program that you've sent worked fine.
This is apparently broken under Kestrel-beta. So that should be
a good news !!.

Regards,
Sandeep
----------------- Original Bug Report-------------------

category : java
subcategory : classes_lang
type : bug
synopsis : Runtime.addShutdownHook doesn't work...
description : java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O-release, 1.3beta-O-release,
interpreted mode)


1., 2., 3., 4: Exact steps to reproduce the problem:
- try to add a shutdownhook via Runtime.addShutdownHook().
It fails with a problem within native code ;-(

The following example code was written as a workaround of the problem,
but the
next issue is that not all signals like "dumb users CTRL-C kill" are
catched ;-(

-- snip --

public class ShutdownHook
{
    static class MyHookThread extends Thread
    {
        MyHookThread( String name )
        {
            super( name );
        }
        
        public void run()
        {
            System.err.println( "shutting down `" + getName() + "`." );
        }
    }
    
    
    public static void addShutdownHook( Thread hook )
        throws IllegalArgumentException,
               IllegalStateException,
               SecurityException
    {
        try
        {
          Runtime.getRuntime().addShutdownHook( hook );
        }
        /* this is to catch a bug in "JDK 1.3 beta". Trying to add the
shutdownHook results in this exception:
         *  Exception in thread "main"
java.lang.IllegalArgumentException: Unknown signal: HUP
         *      at sun.misc.Signal.<init>(Signal.java:133)
         *      at java.lang.Terminator.setup(Terminator.java:46)
         *      at java.lang.Shutdown.add(Shutdown.java:92)
         *      at java.lang.Runtime.addShutdownHook(Runtime.java:197)
         *      at ShutdownHook.main(ShutdownHook.java:27)
         */
        catch( IllegalArgumentException exc )
        {
          boolean throwAgain = true;
          String  msg        = exc.getMessage();
          
          if( msg != null )
          {
            if( msg.equals( "Unknown signal: HUP" ) )
              throwAgain = false;
          }
          
          // re-throw the exc if it doesn't match our specs above...
          if( throwAgain )
          {
            throw exc;
          }
        }
    }
    
    
    public static void main( String args[] )
    {
        d( "start." );
        
        d( "creating hooks..." );
        Thread hook1 = new MyHookThread( "hook1" );
        Thread hook2 = new MyHookThread( "hook2" );
        
        d( "adding hooks..." );
        addShutdownHook( hook1 );
        addShutdownHook( hook2 );
        
        d( "sleeping 5 sec..." );
        try
        {
          Thread.sleep( 5 * 1000 );
        }
        catch( InterruptedException exc )
        {
          d( "sleep interrupted ;-(" );
        }
        
        d( "exit..." );
        System.exit( 0 );
    }
    
    
    static void d( String s )
    {
        System.err.println( "ShutdownHook: " + s );
    }
}
-- snip --

5. --
workaround : Partial workround: See above. All hooks gets registered and
are called at
System.exit(*);, but signals aren't catched my this method ;-(
Full workaround: Spend 10 mins on the native code and fix it - or send
me the
source, please...

Thanks to this bug, my users can kill their jigsaw WWW servers and
connected
beans without a clean shutdown, causing a LOT OF TROUBLE here to repair
those
mistakes by hand (more correct: on hands and knees ;-(((  ).
suggested_val : 
cust_name : Roland Mainz
cust_email : Roland.Mainz@informatik.med.uni-giessen.de
jdcid : <rfe>What about pre-filling this
keyword : betabug
company : University Giessen
release : kestrel-beta
hardware : sun4
OSversion : sol2.7
priority : 4
bugtraqID : 0
dateCreated : 2000-02-02 02:09:31.0
dateEvaluated : 2000-02-02 12:06:33.193

Received on Thursday, 3 February 2000 06:02:09 UTC