tags:

views:

271

answers:

1

If I'm using javaw.exe to launch a Java application, the shutdown hook isn't executed when users log off from their Windows account. The application is actually launched using a launch4j generated .exe file but I know it uses javaw.exe to start it.

This seems to be a known bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4302814

Has anyone else had this problem? If so, how did you fix it?

Thanks!

+1  A: 

The application is actually launched using a launch4j generated .exe file but I know it uses javaw.exe to start it.

I haven't used launch4j in a while, but I'd be fairly suprised if it directly did this. Most of these apps start the jvm themselves, rather than shelling out to javaw.

The only difference between java.exe and javaw.exe is that java.exe automatically attaches a console. The bug that you reference (and the others referenced by it) were closed as Sun doesn't appear to be interested in making the handling of Windows logoff events better. From what I can tell, it only works with java.exe, because the console itself handles the WM_MESSAGES in such a way that it slows down the shutdown process.

It appears that the only easy workaround at the moment is to change the "headerType" in your launch4j config to "console". Obviously, this brings with it an ugly console.

I think the other alternative would be to use some sort of native wrapper of your on that handles windows messages in a cleaner way.

jsight
There's no trace of JNI_CreateJavaVM in the launch4j code. I think this file contains the code that starts it:http://launch4j.cvs.sourceforge.net/viewvc/launch4j/launch4j/head_src/head.c?view=markup
Nicu
@nicu - Yikes, I didn't realize that. Doesn't that mean that the process will show up as "javaw.exe" in the task list? Anyway, does setting "stayAlive" to true help at all? If not, I suspect you would be stuck with capturing the WM messages yourself in native code. :(
jsight
@jsight - Thanks for taking the time to write. I was hoping there is an easy solution to this problem so that I don't have to write my own launcher.1. Launch4j changes the process name so javaw.exe will not appear in the task list.2. The stayAlive setting doesn't help. It just leads to two processes with the same name in the task list.
Nicu