2.3.7 Implementing a batch application (Batch application creation rules)
A batch application is a Java application with the implemented contents of batch processing. This subsection describes the rules for creating batch applications.
- Organization of this subsection
(1) File format of a batch application
You set up a batch application in the class file format specified in JavaVM. When using multiple classes, you can also perform the following:
-
Include a directory with the deployed class file, in class path.
-
Include a JAR file with the archived class file is archived, in class path.
(2) Processing that can be implemented in a batch application
In a batch application, you can implement the processing that can be coded in Java. However, there are some points to be considered when using the threads that are used in file operations or batch applications. For details on the points to be considered when creating an application, see 2.3.11 Points to be considered when creating a batch application.
(3) Starting batch processing
Define one of the following methods in the batch application, as a method to start batch processing:
-
public static void main(String[])
-
public static int main(String[])
You cannot execute a batch application, if the return value type of the main method and modifier are different. You can specify throws in the main method. The arguments specified in the cjexecjob command are passed to the arguments of the main method by a string array.
If you have enabled the use of the JavaVM end method, the batch server creates a batch application execution start thread and registers the thread in a thread group (batchThreadGroup). You can use the JavaVM end method if true is specified in the ejbserver.batch.application.exit.enabled parameter in the Easy Setup definition file. For details on how to set up the ejbserver.batch.application.exit.enabled parameter, see 2.3.10 Settings in the execution environment (batch server settings).
(4) Ending batch processing
Processing ends when the batch application state changes to one of the following states:
-
Execution of the main method of the class specified in arguments of the cjexecjob command ends.
-
An exception or error is thrown outside the main method.
A thread of the batch application (thread belonging to batchThreadGroup) ends when the state changes to one of the following states.
-
If you invoke the JavaVM end method.
-
If the main method returns.
-
If an exception occurred in the main thread is not caught.
The following table describes end processing that you can execute when ending a batch application.
Method of closing a batch application |
End processing that you can use |
||
---|---|---|---|
java.io.deleteOnExit |
Shutdown hook |
||
Ending the application by invoking JavaVM end method |
Ending the application by invoking java.lang.System.exit(int) |
Y |
Y |
Ending the application by invoking java.lang.Runtime.exit(int) |
Y |
Y |
|
Ending the application by invoking java.lang.Runtime.halt(int) |
Y |
N |
|
Ending the application with Ctrl+C |
N |
N |
|
Ending the application due to returning of the main method |
Y |
Y |
|
Ending the application due to exception in the main thread |
Y |
Y |
Legend:
Y: Can be used
N: Cannot be used
You can use the JavaVM end method, if true is specified in the ejbserver.batch.application.exit.enabled parameter in the Easy Setup definition file. For details on the settings of the ejbserver.batch.application.exit.enabled parameter, see 2.3.10 Settings in the execution environment (batch server settings).