L.4 Sample programs of Enterprise Bean (Timer Service)
The sample program for executing the Timer Service is stored in the following directory:
Cosminexus-installation-directory\CC\examples\ejb\timerservice
Following is the overview and execution procedure of the sample:
- Organization of this subsection
(1) Overview of Enterprise Bean (Timer Service) sample programs
The following figure shows the configuration of the Timer Service sample program "TimerService":
You can use this sample program to create, list, and cancel EJB timer through the Web browser. If timeout occurs for EJB timer, a message is output to the user log.
Following is the execution example of the sample program.
The sample provides the following functionalities:
-
Creating the EJB timer
An EJB timer is created when the application starts. Specify the <load-on-startup> tag in the DD for servlet, and the init method of servlet calls Stateless Session Bean method for creating the EJB timer.
Moreover, an EJB timer is created when you specify Web page EJB timer classification, timeout time, and string information, and click the Create button.
-
Displaying the list of EJB timers
A list of EJB timers is displayed on the Web page. The latest list of EJB timers is displayed when you click the Refresh button.
-
Cancelling the EJB timer
When you click the Cancel button on the Web page, the corresponding EJB timer is cancelled.
-
Outputting to the user log
When EJB timer reaches the timeout date and time, the timeout method is called and a message is output to the user log. The following example shows an output of the message:
The timeout method was invoked. (Information = MyTimer02)
(2) Execution procedure of Enterprise Bean (Timer Service) sample programs
The following procedure describes the method of executing sample programs:
(a) Compiling sample programs
Compile sample programs by using a batch file (compile.bat) provided in the sample. This batch file creates EJB-JAR file (timerservice.jar), WAR file (timerservice.war), and EAR file (timerservice.ear).
(b) Setting the J2EE server
(c) Customizing the J2EE server
(d) Starting the J2EE server
(e) Deploying the application
See Appendix L.1(5) Importing, setting and starting the application.
(f) Executing the application
Start the browser and specify the following string in the URL:
http://Machine-name: Port-number/ContextRoot/TimerServiceServlet
When accessing the NIO HTTP server of the J2EE server directly, specify the URL as follows if using the default port:
http://localhost:8008/timerservice/TimerServiceServlet