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?
Asked
Active
Viewed 144 times
1

sharp
- 1,191
- 14
- 39

user3235815
- 91
- 7
-
2The shutdown hook is not for PC shutdown, it is for the shutdown of the JVM. And it will only work if the JVM is shutdown, not in the case of PC shutdown. – Procrastinator Nov 23 '17 at 09:11
-
Which platform? – cbr Nov 24 '17 at 14:19
-
windows os platform – user3235815 Nov 24 '17 at 19:15
-
But if the os is shut down then in turn the JVM gets shut down too =) – kvr Nov 26 '17 at 03:23
1 Answers
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