在db表空间错误上关闭spring boot应用程序

时间:2017-12-05 13:17:37

标签: java spring spring-boot applicationcontext application-shutdown

我的Spring Boot应用程序中有以下预定的代码:

 switch (what) {
            case Android.Media.MediaInfo.BufferingStart:
                //AppLog.showLogE(TAG,"Buffering...");
                progressView.Visibility=(ViewStates.Visible);
                break;
            case Android.Media.MediaInfo.BufferingEnd:
                //AppLog.showLogE(TAG,"Buffering End");
                progressView.Visibility=(ViewStates.Gone);
                break;
        }

在我的private static String getWithoutRepetitions(String sentence){ String result = sentence; String[] allWords = (sentence.replaceAll(",", " ").replaceAll("\\.", " ")).split(" "); HashMap<String, Integer> pairs = new HashMap<>(); for(String s : allWords){ if(pairs.get(s) == null && s != null){ pairs.put(s, 1); }else{ pairs.put(s, pairs.get(s)+1); } } for (Entry<String, Integer> entry : pairs.entrySet()) { String key = entry.getKey(); Integer value = (Integer) entry.getValue(); if(value > 1){ result = result.replaceAll(key, ""); } } result = result.trim().replaceAll(" +", " "); return result; } 组件中,<?php $con = mysqli_connect("****", "****", "*****", "*****"); $id = $_POST["ID"]; $paxfwdcabin = $_POST["PAXFWDCABIN"]; $paxmidcabin = $_POST["PAXMIDCABIN"]; $paxaftcabin = $_POST["PAXAFTCABIN"]; $forwardhold1 = $_POST["FORWARDHOLD1"]; $forwardhold2 = $_POST["FORWARDHOLD2"]; $afthold3 = $_POST["AFTHOLD3"]; $childadjustments = $_POST["CHILDADJUSTMENTS"]; $statement = mysqli_prepare($con, "SELECT * FROM RyanAirCWBalance WHERE ID = ? "); mysqli_stmt_bind_param($statement, "i", $id); mysqli_stmt_execute($statement); mysqli_stmt_store_result($statement); mysqli_stmt_bind_param($statment, $id, $paxfwdcabin, $paxmidcabin, $paxaftcabin, $forwardhold1, $forwardhold2, $afthold3, $childadjustments); $response = array(); $response["success"] = false; while(mysqli_stmt_fetch($statement)) { $response["success"] = true; $response["ID"] = $id; $response["PAXFWDCABIN"] = $paxfwdcabin; $response["PAXMIDCABIN"] = $paxmidcabin; $response["PAXAFTCABIN"] = $paxaftcabin; $response["FORWARDHOLD1"] = $forwardhold1; $response["FORWARDHOLD2"] = $forwardhold2; $response["AFTHOLD3"] = $afthold3; $response["CHILDADJUSTMENTS"] = $childadjustments; } echo json_encode($response); ?> 看起来像这样:

@Scheduled(fixedDelay = DELAY_SECONDS)
private void processJobQueue() {

    BlockingQueue<ReportDeliverable> jobQueue = JobQueueFactory.getJobQueueInstance();

    while (!jobQueue.isEmpty()) {

        //do stuff
        if (rCount == 0) {

            status = send(reportDeliverable);

            if (status == TransferStatus.FAILURE) { 
                populateQueue(reportDeliverable);
            }

            if (status == TransferStatus.SUCCESS) { //write the metadata to database

                int i = dbMetadataWriter.writeMetadata(reportDeliverable);

            }
        } else if (rCount == -1) {
            populateQueue(reportDeliverable);
        } else
            logger.info("Record exists in MetaData for {}. Ignoring the File transfer....", reportDeliverable.getFilePath());
    }

}

在某些情况下,当将插入数据写入数据库时​​,我得到数据库的表空间问题,此时我认为关闭spring启动应用程序直到表空间问题得到解决是明智的。

处理这些罕见案件的正确方法是什么?我可以使用什么技术来优雅地关闭spring启动应用程序,如何在上面的代码中执行此操作?

我的入口点类,我在处理之前最初验证所有数据库连接等,具有以下内容......

DBMetadataWriter

1 个答案:

答案 0 :(得分:0)

你在SpringApplication类上有exit()方法,它可以用来优雅地退出Spring启动应用程序。

它需要2个参数:

  1. ApplicationContext
  2. ExitCodeGenerator
  3. 进一步阅读:

    1. https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/SpringApplication.html#exit-org.springframework.context.ApplicationContext-org.springframework.boot.ExitCodeGenerator...-
    2. 代码示例:

      @Autowired
      public void shutDown(ExecutorServiceExitCodeGenerator exitCodeGenerator) {
          SpringApplication.exit(applicationContext, exitCodeGenerator);
      }
      

      当您获得No Table space

      的异常时调用此方法