Skip to main content
1-Visitor
January 14, 2010
Question

JVM shutdown hook not working in custom JVM within Editor 5.3

  • January 14, 2010
  • 0 replies
  • 485 views
I'm off the standard JVM when running Editor 5.3. We use either:


# Java VM Version 11.2-b01 -- Sun Microsystems Inc.
set javavmpath= 'C:\Program
Files\Java\jdk1.6.0_12\jre\bin\client\jvm.dll';

# Java VM Version 14.1-b02 -- Sun Microsystems Inc.
set javavmpath= 'C:\Program Files\Java\jre6\bin\client\jvm.dll';

My results are the same for either version of the JVM.

If anyone is interested in this esoteric problem, then I invite them to
test on their platform (with the stock JVM shipped with their version)
and report their results.

I've been trying to take advantage of the Java method
"File.createTempFile(...)" where the temporary file thus created can be
flagged for automatic destruction upon the termination of the JVM by
calling the "deleteOnExit()" method.

Unfortunately, it appears this may not work in Windows due to two bugs.
A work-around has been proposed at:


machine, as defined by the Java Language Specification."

I'm wondering what needs to be done to make the sample program below work.

To that end, I have created a sample file which demonstrates that the
shutdown hook works in a JVM you create in a DOS console whereas in the
Arbortext JVM, it does not. Unfortunately, I cannot find documentation
or code relating to the shutdown of the JVM within Editor.

vvvvvvvvvvvvvvvvvvv start of text copy vvvvvvvvvvvvvvvvvvvvvvv

/*

To test capturing JVM shutdown in Arbortext

save this file as TrapBreak.java
In the directory where this file is located copy/paste
into the console once to set the environment:

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_12
set PATH=%PATH%;C:\Program Files\Java\jdk1.6.0_12\bin

Then use these three commands in console:

javac TrapBreak.java
copy /Y *.class "C:\Program Files\Arbortext\Editor\custom\classes"
REM try running this in the DOS console to confirm the hook works in
a generic JVM
java TrapBreak

Need to load this class inn Editor's JVM, copy the lines below into
the console:

global arr[];
global javarr = java_array_from_acl($arr, '[Ljava/lang/String;');
java_static('TrapBreak','main',$javarr);

*/
import java.io.*;
import java.util.Date;

public class TrapBreak {
public static boolean debug = true;

public static void main(String args[]) throws Exception{
new TrapBreak().doit();
if (debug == true){
System.out.println("TrapBack hook registered.");
}
}

public void doit() throws Exception {
Runtime.getRuntime().addShutdownHook(
new Thread() {
public void run() {
// the output below probably may never be seen as
the console will disappear.
System.out.println("TrapBreak activated.");
try{
// Reminder: make sure do you have a C:\\Temp
directory
// FileWriter: 2nd param: true = append mode
FileWriter fstream = new
FileWriter("C:\\Temp\\Arbortext_JavaTrapBreak.log", true);
BufferedWriter out = new BufferedWriter(fstream);
out.write((new java.util.Date()) + " TrapBreak
invoked at shutdown.\n");
out.close();
} catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
if (debug == true){
int mseconds = 1000;
System.out.println("Sleeping for " + (mseconds/1000)
+ " seconds so prior output may be viewed.");
try {
Thread.sleep(mseconds);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
}
);
}
}

^^^^^^^^^^^^^^^^^^^^^^^^^^^^ end of text copy
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Suggestions and/or your results?

--



Oracle Email Signature Logo
John Laurence Poole | Principal Software Engineer | 650.607.0853
Oracle User Assistance Engineering
M/S 2op1070
500 Oracle Parkway
Redwood Shores CA 94065-1677

Oracle Instant Chat: john.poole

The statements and opinions expressed here are my own and do
not necessarily represent those of Oracle Corporation.