1

I want to write a java application that hides in system tray and measures bandwidth traffic. I want before the PC shutdowns, to save traffic size to file. I use shutdownHook in java but it does not work. How to write code with JNA to call save function in my java code before PC shuts down?

sharp
  • 1,191
  • 14
  • 39

1 Answers1

1

That answer do what you want, anyway for your case I suggest just create a Interval task that calculates and save that data because you must to have in mind that if a unexpected behavior like the power is gone or blue screen happen then you will lost data because the shutdown hook will not be called.

while(true){
    System.out.println("calculating and saving traffic");
    TimeUnit.SECONDS.sleep(10);
}
deFreitas
  • 4,196
  • 2
  • 33
  • 43