How to ensure a piece of code is run before exiting a java application

后端 未结 4 2066
庸人自扰
庸人自扰 2021-01-13 00:42

I\'m using a licensed API which has a method to acquire/release a license object from a license server that has a finite number of licenses. At the beginning of my applicati

4条回答
  •  情深已故
    2021-01-13 01:35

    you achieve this by never calling Sytem.exit(). In main() you create a "last line of defense" with

     try {
        startApp();
     } catch (Exception ex) {
          // do some logging
     } finally {
        releaseLicense();
     }
    

提交回复
热议问题