P
Paul J. Lucas
I'm looking at the source code for the 'java' command-line tool
written in C. Near the bottom of main(), it calls the static
main() method of the main Java class via CallStaticVoidMethod().
It then detaches the current thread and destroys the JVM via
DestroyJavaVM().
The thing I don't understand is what if the Java main class's
main() spawns a thread, runs in that thread, whereas the
original thread returns from main() and dies. The call to
CallStaticVoidMethod() will then return and the C code will
continue, and then call DestroyJavaVM() effectively killing the
JVM out from under the still-running Java program.
This is what can happen in a Java Swing application where its
main() creates the AWT event thread and the application runs in
it, yet the original thread returns from main().
So how does this work? How is the call to DestroyJavaVM()
deferred?
- Paul
written in C. Near the bottom of main(), it calls the static
main() method of the main Java class via CallStaticVoidMethod().
It then detaches the current thread and destroys the JVM via
DestroyJavaVM().
The thing I don't understand is what if the Java main class's
main() spawns a thread, runs in that thread, whereas the
original thread returns from main() and dies. The call to
CallStaticVoidMethod() will then return and the C code will
continue, and then call DestroyJavaVM() effectively killing the
JVM out from under the still-running Java program.
This is what can happen in a Java Swing application where its
main() creates the AWT event thread and the application runs in
it, yet the original thread returns from main().
So how does this work? How is the call to DestroyJavaVM()
deferred?
- Paul