开发者

design pattern for determine if an app has shutdown cleanly

开发者 https://www.devze.com 2023-03-08 21:19 出处:网络
what\'s the best design pattern to check to see if an app has shutdown cleanly(eg. didn\'t crash)? It seems creating a lock file in the current directory and deleting the file upon normal shutdown is

what's the best design pattern to check to see if an app has shutdown cleanly(eg. didn't crash)?

It seems creating a lock file in the current directory and deleting the file upon normal shutdown is a goo开发者_Go百科d way, or is it?

are there better ways? The app is in java, so I plan to add a shutdown hook to the instance to delete the lock file. is this a good way?


Adding a shutdown hook doesn't seem ideal to me, as I'd expect a shutdown hook to still be executed if the application crashed. I'd just make the deletion part of "normal system exit".

But yes, having a file seems pretty reasonable to me. One caveat though - consider what would happen if your application were opened twice or more concurrently. You may want to create a randomly-named file instead of one with a fixed name.

0

精彩评论

暂无评论...
验证码 换一张
取 消