我的 Java 程序是从 Windows 脚本调用的。
是否可以使用 Java 退出代码来确定 Java 程序是否因磁盘空间不足而提前终止,同时它仍在从 JAR 文件加载类文件?
我尝试了内存不足异常,它返回退出代码 1,但磁盘空间不足返回退出代码 0。这是正确的行为吗?
子类方法:
public int executeBatch() {
logger.info("executeBatch() - Send Email Alert Start");
try {
alertTransactionMgr.sendEmailAlert();
} catch (Exception e) {
throw new Exception(e);
}
logger.info("executeBatch() - Send Email Alert End");
return 0;
}
父方法:
public int execute() {
this.trx = createTransaction();
try {
returnCode = executeBatch();
} catch (Exception e) {
printLogErrorMsg("Job Failed caused by the Exception.", e);
returnCode = -1;
trx.setStatus("Failure");
updateBatchTransaction(trx);
}
return returnCode;
}
Windows 批处理脚本
@echo off
set ERRLVL=0
java -cp %CLASSPATH% com.test.runner.MainBatchRunner
if not (%ERRORLEVEL%)==() (
set ERRLVL=%ERRORLEVEL%
)
echo Delete Files that are more than 30 old
forfiles /p "%BATCH_LOG_DIR%" /s /m %2*.log /d -%ARCHIVE_DAYS% /c "cmd /c echo del %BATCH_LOG_DIR%\@file"
forfiles /p "%BATCH_LOG_DIR%" /s /m %2*.log /d -%ARCHIVE_DAYS% /c "cmd /c del %BATCH_LOG_DIR%\@file"
echo Program exit %ERRLVL%
echo Program exit %ERRLVL% >> %BATCH_LOG_FILE%
exit /B %ERRLVL%
内存不足的输出:
[信息][2015-06-29 18:05:01,960][org.springframework.context.support.ClassPathXmlApplicationContext] - 刷新 org.springframework.context.support.ClassPathXmlApplicationContext@4b222f:显示名称 [org.springframework.context.support .ClassPathXmlApplicationContext@4b222f];启动日期 [2015 年 6 月 29 日星期一 18:05:01 SGT];上下文层次结构的根
[INFO ][2015-06-29 18:05:02,050][org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - 从文件加载 XML bean 定义 [D:\batch\dev\batch_home\bin\spring\applicationContext -测试.xml]
删除超过 30 个的旧文件
del D:\batch\dev\batch_home\log\"TEST_20150629_173016.log"
程序出口1
磁盘空间不足的输出:
[信息][2015-06-29 19:05:01,960][org.springframework.context.support.ClassPathXmlApplicationContext] - 刷新 org.springframework.context.support.ClassPathXmlApplicationContext@4b222f:显示名称 [org.springframework.context.support .ClassPathXmlApplicationContext@4b222f];启动日期 [2015 年 6 月 29 日星期一 19:05:01 SGT];上下文层次结构的根
[INFO ][2015-06-29 19:05:02,050][org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - 从文件加载 XML bean 定义 [D:\batch\dev\batch_home\bin\spring\applicationContext -测试.xml]
删除超过 30 个的旧文件
del D:\batch\dev\batch_home\log\"TEST1_20150629_180030.log"
程序出口0