Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2003

Tip: Looking for answers? Try searching our database.

windowClosing / windowClosed when logging off or shutting down Windows...

Thread view: 
Will Atkinson - 29 Nov 2003 21:31 GMT
Hi All,

Sorry to post a 'Windows specific' question, although it may well
apply to other operating systems.

I have written a program that times tasks, and it can quite easily be
in the process of timing a task when the user logs off or shuts down
Windows.  Currently, it persists out a list of the timed tasks when
windowClosing / windowClosed occurs, (i.e. when the user closes the
program explicitly) but neither of these occur in the case of a log
off / shut down.

Is there any way of determining that the JVM is in the process of
terminating from withing a Java application?  I'm guessing that using
'finalize' in my main class isn't going to help, as I know finalize
doesn't necessarily get called.

I'm sure there must be a fairly simple solution to the problem of
users losing timing information when closing by a log off / shutdown -
but I can't find it!

Any help much appreciated!

LemonSmasher.
Andrew Thompson - 29 Nov 2003 23:20 GMT
..
> I have written a program that times tasks, and it can quite easily be
> in the process of timing a task when the user logs off or shuts down
> Windows.
...
> Is there any way of determining that the JVM is in the process of
> terminating from withing a Java application?

Runtime.addShutdownHook(Thread t) may be what you
are looking for (I have not used it yet)

HTH

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Will Atkinson - 01 Dec 2003 18:57 GMT
> ..
> > I have written a program that times tasks, and it can quite easily be
[quoted text clipped - 8 lines]
>
> HTH

Thanks for you help, Andrew - that sounded like it should have done
the trick, and indeed, had I been running my program using java.exe I
suspect it would have, but a little bit of experimentation with
java/javaw seems to indicate that, for javaw.exe, the shutdown hook
does not get called, whereas for java.exe it does.  :(

I'm going to try updating to the latest JVM, just in case it's a bug
that has been fixed.  I'll post back my findings...
Will Atkinson - 02 Dec 2003 08:26 GMT
> > ..
> > > I have written a program that times tasks, and it can quite easily be
[quoted text clipped - 17 lines]
> I'm going to try updating to the latest JVM, just in case it's a bug
> that has been fixed.  I'll post back my findings...

No luck - and a search through Sun's bug database reveals that this is
a longstanding issue with javaw.exe (java.exe does not exhibit this
problem, however, it does display an unsightly console window whilst
running on Windows).

I'll see whether I can find any decent workarounds for this problem.
:(


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.