Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4485742
Votes 0
Synopsis Process.destroy() and shutdown hook platform specific behavior
Category java:classes_lang
Reported Against 1.3.1
Release Fixed
State 11-Closed, Not a Defect, bug
Priority: 4-Low
Related Bugs
Submit Date 29-JUL-2001
Description




[also see bug # 4412451]
-------
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

Scenario:

1) MyClass1 sets in its constructor a shutdown hook and the main method of
MyClass1 calls this constructor.
2) A MyClass2 main method creates a new process using Runtime.exec() method
with as the command line a java command with as the main class MyClass1.
The retured  customer  by the Runtime.exec() method is the Process  customer  on the
MyClass1 runtime.
3) We call Process.destroy() method on the MyClass1 Process  customer .

Here 2 different behaviors are obesrved:
1) On Solaris the shutdown hook is triggered
2) Whereas on NT it is not.

Problem: The behavior of the Process.destroy() method differs on NT and Solaris
OS.
(Review ID: 127844) 
======================================================================
Work Around
N/A
Evaluation
Not a bug. Using Process.destroy() is the last resort, and there is no
garantee that shutdown hooks will be run in the case when the process is
another VM instance.  In particular, on Windows, we use TerminateProcess()
call, which terminates the process abruptly. We could use softer ExitProcess()
call, which would allow to run shutdown hooks, but ExitProcess could block on 
stubborn processes. Since Process.destroy() is the last resort, using
TerminateProcess() in it is justified. No garantees can be made
with respect to a programming technique, which  relies on using 
shutdown hooks and Process.destroy().


  xxxxx@xxxxx   2001-08-15
Comments
  
  Include a link with my name & email   

Submitted On 28-OCT-2001
jerhewet
> We could use softer ExitProcess() call, which would allow 
> to run shutdown hooks, but ExitProcess could block on
> stubborn processes. Since Process.destroy() is the last
> resort, using TerminateProcess() in it is justified.

So why not give us both options -- a Process.exit() that 
calls ExitProcess() and a Process.destroy() that calls 
TerminateProcess() to whack stubborn ones that don't 
respond to exit()?

I've already had to write external code to work around the 
bug you refuse to fix regarding console windows and the 
SW_HIDE parameter.  So now I have to waste even more time 
figuring out how to work around your call to 
TerminateProcess()?

Your own RMID and RMIREGISTRY applications are sterling 
examples of why I'm having to jump through these hoops.  
There isn't any way to cleanly stop them from the command 
line, and I certainly don't want to exec() them directly 
and have those damned DOS console windows cluttering up my 
screen until I destroy() them.

Add a method to call ExitProcess(), fix the SW_HIDE 
problem, and give us some way to stop RMID and RMIREGISTRY 
from the command line.


Submitted On 11-DEC-2001
mnewcomb
That is wierd...  I see the exact opposite behavior!  My 
subprocess registered shutdown hooks get called on Windows 
NT, but not on Solaris!

I have a similar issue when using Ant (java build system 
from Apache) to run processes.  When I ctrl-C from Ant, I 
want it to kill the subprocesses it is running with 
Process.destroy().  I made a patch and a test case in which 
a process is execed form Ant and that process registers a 
shutdown hook with the VM.

When I run and hit ctrl-C, Ant's shutdown hook is called 
and that calls Process.destroy() on all subprocesses.  My 
subprocesses get the message on Windows NT, but they don't 
on unix-based JDKs (tried RedHat 7.2 and Solaris 7) both 
with the same JDK you are using (1.3.1-b24).

How screwy is that?  When I do a kill (which sends SIGTERM) 
on the subprocess, my shutdown hooks get called.  That 
means that on unix-based JVMs, Process.destroy() is sending 
SIGKILL because they aren't seeing the signal!

We both have the same JDK?  What's up with that?


Submitted On 13-FEB-2002
simtt8
And I lose 5 hours on other NT behaviour:
   if i start other VM using Runtime.exec indirectly:  Runtime.exec("test.cmd"); (Test.cmd calls java.exe as 
VM)
   I CAN'T DESTROY second VM using process.destroy(); Then it apply only on CMD.EXE, but grandchild 
process java.exe (menas VM) still active!! 
Direct call of second VM using Runtime.Exec(..java.exe..) work completly correct related process.destroy() !
So poeple, have fun !


Submitted On 15-JUL-2003
conor
I don't think the "Not a bug" response is satisfactory.
Please see this Apache Ant bug report 
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8510

In effect, we can't gracefully shutdown Java processes
launched from Ant on Windows. The platform specific
limitation seems at odds with Java's goals.


Submitted On 28-AUG-2007
uuklanger
This issue affects SystemTray and TrayIcon.  A process that uses this needs to know when the JVM shutsdown so things link file, database, and network connections can be shutdown.

shutdownHook (or similar) needs to be available for all supported OS for when a user logs off or a system shutdown happens.



PLEASE NOTE: JDK6 is formerly known as Project Mustang