This is kind of an experiment on my part and not absolutely critical if it can't be done easily, but I'm wondering if it's possible to launch separate jvm processes from an already existing jvm process. The reason I want to do this is to be able to compare the behavior and performance of certain global settings side by side. For example I run my "launcher" app, set my settings such as sun.java2d.noddraw true or false, click a button and then launch the new window with the approprate settings enabled. Then I can launch as many processes as I want observe their behavior/appearance and then clean them all up by just closing the launcher/master application.

Anway, can this be done or is it more trouble than it's worth. Thanks for any help.

Windows doesn't (usually) maintain a parent/child relationship between processes. This means that closing the parent does not close the children. You could register a shutdown task in the parent and explicitly kill any remaining children during the parent process shutdown. On Unix/Linux of course killing the parent does kill all its children.

Thank You the information so far has been very helpful. I have a couple of questions, however, that I haven't been able to sort out. For instance, the java docs state for Runtime.exec():

Quote

If envp is null, the subprocess inherits the environment settings of the current process

However, I am unable to successfully launch the new process without explicitly settings the classpath in the environment argument. Shouldn't it be able to figure it out from the current process as it states?

Second, I can't seem to register a shutdown task through addShutdownHook. Is this not the correct function to use?

Second, I can't seem to register a shutdown task through addShutdownHook. Is this not the correct function to use?

What goes wrong when you try? Note that shutdown hooks will only be run if the process is terminated nicely. Killing the process from Task manager does not give the JVM an opportunity to do any cleanup. The same applies if you kill it from an IDE. If the process is run using java.exe from a command prompt then Ctrl-C will allow the cleanup to take place. Similarly if you call System.exit() from within the process.

As to the environment, I just use the exec variants which don't require passing it and don't have any problem.

Thank You the information so far has been very helpful. For instance, the java docs state for Runtime.exec():However, I am unable to successfully launch the new process without explicitly settings the classpath in the environment argument. Shouldn't it be able to figure it out from the current process as it states?

Not if its not in your shell ENVIRONMENT variables.

For instance if you are using -classpath on your command line.

Got a question about Java and game programming? Just new to the Java Game Development Community? Try my FAQ. Its likely you'll learn something!

Note that shutdown hooks will only be run if the process is terminated nicely

D'oh! That's it. For some reason, I had it in my head that terminating it from my IDE was like hitting Ctrl-C from cmd, but I can see why that wouldn't be the case and goes with what you said before about Windows not killing child processes.

Quote

Not if its not in your shell ENVIRONMENT variables

Makes sense. I guess it's not really that big of a deal to set an explicit path for this, but since the type A side of me needs to be appeased, I found that

Note that shutdown hooks will only be run if the process is terminated nicely.

Unfortunately it seems the Sun JVM does not process either the WM_ENDSESSION or WM_QUIT messages correctly. As result shutdown processing is unreliable for processes with a message loop (anything gui). Even worse the Sun engineers do not seem to understand the issue. (see bugs 4486580 and 4302814).

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org