Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Detect windows shutdown

 
Maki Jav
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to gracefully exit my Java program that runs as a background service on windows shutdown. No Dialogs at shutdown announcing that This program must be exit... No computer hangups...

Can JACOB or JAWIN help me in this regard?

Thanx in Advance,

Maki Jav
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had similar problem with a Java proxy server.
I solved it by creting an empty invisible AWT window, calling pack() on it and adding WindowListener to it. It will receive windowClosing event on windows shutdown.

I seems that on Windows, a window is requires even for some nonGUI tasks. Maybe that's why the OS is called Windows.
 
Maki Jav
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Valdo,

Following ur idea I have come up with this class

I am writing messages to a file in that method of TestRunMethod class.

This class is working for windows 98 ie when I logoff, restart or shutdown

This class will be helpful to others too.

Batch file running this has code

C:\jdk1.3\bin\javaw.exe TestAwtWindow
EXIT

So when windows is exiting no command prompt is present to halt it on the way.

Thanks once again.

Maki Jav
 
Michael Lloyd Lee
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with using a shutdown hook?

Should your application really care if the system is being shut down, or just your application is being shutdown?
[ October 14, 2005: Message edited by: Michael Lloyd Lee ]
 
Maki Jav
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with shutdown hook is that I could get it respond to user using
CTRL + C keys on a command prompt window running my java app. It did not do anything if user closes it by clicking on X (close). What if my non gui java app is running invisibly?

My application has to do some things on system shutdown...

ShutdownHook does not respond to system shutdowns...



Maki Jav
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic