0

Ive got the following ShutdownHook to detect when the application is exited:

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        public void run() {

            // Do what you want when the application is stopping
            sendMsg("", "goOfflineExit", "12");
        }
    }));

This works perfectly on Mac os but for some reason nothing gets fired on Windows.

Any ideas what im missing?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Alosyius
  • 8,771
  • 26
  • 76
  • 120

1 Answers1

3

I can think of two possible explanations:

  • The sendMsg(...) call may be happening too late; e.g. after streams have been closed or flushed.

  • The sendMsg(...) call may be throwing an exception. Uncaught exceptions thrown in a shutdown hook typically don't get reported.

If you showed us the code of sendMsg we might be able to figure out a more definite answer.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216