Name: skT88420 Date: 01/05/2000
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
/*
<pre>
Bug Report
no shutdown event handling in Windows with javaw.exe
[symptom]
On Windows, with javaw.exe, the shutdown handler which has been registered
by java.lang.Runtime#addShutdownHook() is not called in OS shutdown phase.
[Environment]
OS: Microsoft Windows NT 4.0 SP4 Japanese version
JVM:
# java.exe -version
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
[to reproduce]
- compile attached class
# javac ShutdownHandlerThread.java
- make shortcut in the Windows' startup folder
$(windir)\Profiles\$(login_user)\startmenu\program\startup\kick.lnk
with link-point
"C:\Program Files\JavaSoft\Jre\1.3\bin\javaw.exe" ShutdownHandlerThread
and working folder
"C:\$(directory where ShutdownHandlerThread.class is. Say, c:\Temp )"
- log in Windows and shutdown
- re-login and see the working folder
The file "log.txt" should be created in the working folder but not.
With Window shown version VM "java.exe", it works expectedly, "log.txt"
is left after shutdown.
I do not want to show this DOS prompt because it doesn't add anything
useful to make my Java application which only does shutdown cleaning
tasks.
</pre>
*/
// ShutdownHandlerThread.java
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.IOException;
/**
<pre>
* test program for new shutdown handling function in kestrel
*
* @author AKIMOTO, Hiroki, PFU Ltd.
* @since 1.3Beta
*/
public class ShutdownHandlerThread extends Thread {
public static void main(String[] args) {
// create and register shutdown handler thread
Runtime runtime = Runtime.getRuntime();
ShutdownHandlerThread shutdownHandlerThread = new ShutdownHandlerThread();
runtime.addShutdownHook(shutdownHandlerThread);
try {
// pause main thread to wait shutdown signal
System.out.println("joined");
Thread.currentThread().join();
} catch (InterruptedException ex) {
System.out.println("interrupted");
}
System.out.println("end of main thread (not reached)");
}
/**
* shutdown handler body
* write a file when shutdown
*/
public void run() {
System.out.println("ShutdownHandlerThread is invoked.");
try {
// make footprint
PrintWriter printWriter = new PrintWriter(new FileWriter("log.txt"));
printWriter.println("ShutdownHandlerThread::run() is invoked.");
printWriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/*
</pre>
*/
(Review ID: 99595)
======================================================================