Kill opened IE, when killing Swing Java App

I am creating menu items which fire off an IE window to a URL. However, when app is closed the Java process that runs the app blocks waiting for the executed browser to terminate before its shuts itself down. This has potential repercussions as the Java VM hangs around in the mean time, holding resources. Can anyone point me in the direction of how to kill the opened IE window when I kill the java app? I would greatly appreciate any help. :-)

This is the code in question:

userManualMenuItem.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

try

{

String url = System.getProperty("EASEUserManualURL");

Runtime r= Runtime.getRuntime();

Process p= r.exec("iexplore " + url);

}

catch(Exception exception)

{

Logger.getLogger().logError("Error opening Intenet Explorer to show EASE user manual.\nCause: " + exception.getMessage());

}

}

});

[984 byte] By [gemmytotsa] at [2007-10-3 8:34:41]
# 1
Wouldn't it solve the problem if you made the exec() call on a daemon thread? I wouldn't advise making exec() calls on the EDT in any case.
itchyscratchya at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 2

When the app is killed I am assuming you have some listener triggered (Window Closed or a ActionPerformed listener triggered somewhere, have that listener call destroy on your IE processes below.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Process.html#destroy()

That will kill your launched IE processes. You will have to keep references to your launched IE subprocesses around somewhere as well so you can reference and kill them later when your user wants to close the app.

Hope that helps

AmesIAa at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 3
Presumably, though, the requirement is to allow the VM to close rather than to force the browser to be brought down? Otherwise it'd probably be rather irritating for the user.
itchyscratchya at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 4
I'm assuming the browser opened contains HTML help docs for the Java app running (inferring that from the code he has posted) thus, user wouldn't want browser(s) sticking around that contains help docs for application that has been closed. That's what I'm guessing.
AmesIAa at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 5

Now I actually read the source code that makes sense ;o)

I think I might still find it irritating as a user, though - particularly if I had navigated to some external page. Actually, I'd find the whole thing irritating since I use Mozilla and don't want some dopey app forcing me to use IE :o)

itchyscratchya at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 6
lol - agreed.
AmesIAa at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 7

I agree that FF would be a much better idea (i use it myself) but when working for a large corporate company who only use IE (some of their web apps don't work in anything else) and the fact that my users are IE aware this the reason behind IE.

The fact that the VM runs in the background when the java app is closed means that I either have to kill IE or stop the VM from running.

As I am new to Java I'm stuck! lol

gemmytotsa at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 8
I'm sure there's a way you can just launch the user's default browser isn't there? Anyway, if you're blowing the corporate hose then it's probably a waste of time, just launch IE I guess.Have you tried the daemon thread approach?
itchyscratchya at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 9

> Wouldn't it solve the problem if you made the exec() call on a daemon

> thread? I wouldn't advise making exec() calls on the EDT in any case.

1 - You can't call exec() on a Daemon thread. You can call Runtime.exec() inside of a spawned thread that has been marked as a Daemon. This would be preferably rather than launching off of the EventDispatcherThread as itchystratchy stated because....

http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html

> I'm sure there's a way you can just launch the user's default browser isn't there?

2. - I use http://browserlaunch2.sourceforge.net/in my current app, it launches whatever application you have associated for that file type to view that file. Also supposedly cross platform. You will not get Process reference to the launched app though. I've tested successfully on Win 2000 and XP up to now but it will allow you to close your Java application and leave any launched browsers open if that is what you are looking for or as you asked for earlier keep a collection of launched Process references and destory them when your user is closing your app.

AmesIAa at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...
# 10
You can call Runtime.exec() inside of a spawned thread that has been marked as a Daemon.Yes - sorry, that's what I meant. Should have been clearer.
itchyscratchya at 2007-7-15 3:42:12 > top of Java-index,Desktop,Core GUI APIs...