作家
登录

常见Java应用如何优雅关闭

作者: 来源: 2017-12-19 11:04:37 阅读 我要评论

  •         } 
  •     } 
  • 四、Spring Boot供给的优雅封闭功能

    我们一般采取如下的方法,启动一个Spring boot应用:

    1. public static void main(String[] args) throws Exception {   
    2.     SpringApplication.run(SampleController.class, args); 

    SpringApplication.run()代码如下,会调用到refreshContext(context)办法:

    1. public ConfigurableApplicationContext run(String... args) {   
    2.     StopWatch stopWatch = new StopWatch(); 
    3.     stopWatch.start(); 
    4.     ConfigurableApplicationContext context = null
    5.     FailureAnalyzers analyzers = null
    6.     configureHeadlessProperty(); 
    7.     SpringApplicationRunListeners listeners = getRunListeners(args); 
    8.     listeners.started(); 
    9.     try { 
    10.         ApplicationArguments applicationArguments = new DefaultApplicationArguments( 
    11.                 args); 
    12.         ConfigurableEnvironment environment = prepareEnvironment(listeners, 
    13.                 applicationArguments); 
    14.         Banner printedBanner = printBanner(environment); 
    15.         context = createApplicationContext(); 
    16.         analyzers = new FailureAnalyzers(context); 
    17.         prepareContext(context, environment, listeners, applicationArguments, 
    18.                 printedBanner); 
    19.         refreshContext(context); 
    20.         afterRefresh(context, applicationArguments); 
    21.         listeners.finished(context, null); 
    22.         stopWatch.stop(); 
    23.         if (this.logStartupInfo) { 
    24.             new StartupInfoLogger(this.mainApplicationClass) 
    25.                     .logStarted(getApplicationLog(), stopWatch); 
    26.         } 
    27.         return context; 
    28.     } 
    29.     catch (Throwable ex) { 
    30.         handleRunFailure(context, listeners, analyzers, ex); 
    31.         throw new IllegalStateException(ex); 
    32.     } 

      推荐阅读

      全年盘点:2017数据中心领域的10大新闻事件

    买与卖2017年数据中间市场处于持续变更的状况。客户加快向云端迁徙带来的压力,再加上部件缺乏,使得数据中间>>>详细阅读


    本文标题:常见Java应用如何优雅关闭

    地址:http://www.17bianji.com/lsqh/39920.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)