My Java program is called from a windows script.
Is it possible to use the Java exit code to determine whether the Java program was terminated prematurely due to out of disk space while it is still loading the class files from the JAR file?
I tried out of memory exception and it returns an exit code 1 but out of disk space returns exit code 0. Is this correct behaviour?
Child class method:
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;
}
Parent method:
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 batch script
@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%
Output for OutOfMemory: [INFO ][2015-06-29 18:05:01,960][org.springframework.context.support.ClassPathXmlApplicationContext] - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4b222f: display name [org.springframework.context.support.ClassPathXmlApplicationContext@4b222f]; startup date [Mon Jun 29 18:05:01 SGT 2015]; root of context hierarchy [INFO ][2015-06-29 18:05:02,050][org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from file [D:\batch\dev\batch_home\bin\spring\applicationContext-test.xml]
Delete Files that are more than 30 old
del D:\batch\dev\batch_home\log\"TEST_20150629_173016.log" Program exit 1
Output for Out of disk space: [INFO ][2015-06-29 19:05:01,960][org.springframework.context.support.ClassPathXmlApplicationContext] - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4b222f: display name [org.springframework.context.support.ClassPathXmlApplicationContext@4b222f]; startup date [Mon Jun 29 19:05:01 SGT 2015]; root of context hierarchy [INFO ][2015-06-29 19:05:02,050][org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from file [D:\batch\dev\batch_home\bin\spring\applicationContext-test.xml]
Delete Files that are more than 30 old
del D:\batch\dev\batch_home\log\"TEST1_20150629_180030.log" Program exit 0