Sun Java System logo     
Lifecycle Multi-threaded Application



Lifecycle Multi-threaded Application


This document describes how to utilize the Lifecycle (Multi-threaded) sample application in conjunction with the Sun Java (tm) System Application Server 7.

This sample application document contains the following sections:



Overview

This sample is based on the LifecycleListener interface support provided by Sun Java (tm) System Application Server. This demonstrates the ability of the lifecycle classes to use other server resources like DataSource and UserTransaction using threads.

The following instructions describe how to assemble, deploy on the Application Server, and how to run the application. Although the sample application offers minimal functionality, this sample should provide you with a basic understanding of startup class support in the Sun Java (tm) System Application Server.



Setting up the environment

In order to successfully deploy and run the Lifecycle Multi-threaded sample application, Database resources (PointBase) needs to be setup with the Application Server.

If you want to run the Lifecycle Multithreaded sample application with the Oracle database, please refer to (How to run samples with Oracle database server) for configuration steps.



Compiling and Assembling the Application



This Command Line Based Compilation and Assembly procedure describes how to assemble and compile the sample using a Command Line Interface (CLI).


Command Line Based Compilation and Assembly


To rebuild the entire application from scratch:

  1. Compile and Assemble.

    Execute the asant command under <install_dir>/samples/lifecycle/multithreaded/src/

    [please add <install_dir>/bin to your path]

    The default target core is executed to rebuild the .jar file.

  2. Deploy the application.

    When you have re-created the sample application from scratch, proceed to Deploying the application.

  3. Clean the application project area.

    Execute the asant clean command to remove the sample application's assemble and build directories.

    Now you are ready to use this .jar file for deployment.



Deploying the Sample Application

Select one of the following approaches to deploy the application:

  • Command Line Based Deployment describes how to manually register the application in a Sun Java (tm) System Application Server using a Command Line Interface (CLI). This is the fastest means of deploying the application.

  • GUI Based Deployment describes how to use the Sun Java (tm) System Deployment Tool to import and deploy the sample application.


Command Line Based Deployment

Since a complete .jar file is supplied, the fastest means of setting up the application is to use the command line utilities as described in this section.

If you want to deploy through a GUI tool, follow the instructions for GUI Based Deployment.

The pre-built lifecycle-multithreaded.jar file contains the Java Archive (JAR) files of the application.

Deploy using either the asant script or the asadmin command.


Using the asant Script

  1. Go to the src directory of the sample:

    <install_dir>/samples/lifecycle/multithreaded/src

  2. Execute the asant deploy command.


Using the asadmin Command

  1. Go to the root of the sample directory:

    <install_dir>/samples/lifecycle/multithreaded/

  2. Execute the asadmin command to deploy the application to the local application server instance:

    asadmin create-lifecycle-module -u <user-name> -w <password> -H <hostname> -p <admin server port> --classname samples.lifecycle.multithreaded.LCLWithResourceAccessInThread --classpath <install_dir>/samples/lifecycle/multithreaded/src/../lifecycle-multithreaded.jar lifecycle-multithreaded

The deployment process involves the following operations:

  • It authenticates against the local application server's administrative server.

  • The .jar file is transferred to the administrative server.

  • The administrative server begins the registration process:

    • Parses the .jar file.

    • Explodes the bits into the repository.

    • Registers the J2EE application lifecycle-multithreaded by updating the server.xml file.

      If you want to verify the registration of the application, proceed to the Verifying Registration section.

      Otherwise, you are ready to exercise the application by Running the Sample Application.


GUI Based Deployment

Since a pre-built (.jar) file for the sample application is included with the application server, you can use the Admin Tool to quickly read in the .jar file and deploy it to the application server.

  1. Start the admin server if it is not already started.

    UNIX

    1. Goto <install_dir>/domains/domain1/admin-server/bin.

    2. Execute the startserv command.

    Windows

    1. Goto <install_dir>\domains\domain1\admin-server\bin

    2. Run startserv.

  2. Open the .jar file.

    1. Navigate to the browser based admin server page [http://<server-host>:<admin-port>/index.html].

    2. Enter your username and password to access the admin server.

    3. Click App Server Instances>server1>Applications>Lifecycle Modules.

    4. In the right hand pane, click Deploy to deploy an application.

    5. Fill in the Module Name, Classname and Classpath.

    6. Fill in Load order(Optional). Load order expects integer value which can be used to force the order in which deployed lifecycle modules are loaded at server startup. Smaller numbered modules get loaded sooner. Order is unspecified if two or more lifecycle modules have the same load-order value.

    7. You may also choose the relevent boolean values for Fatal faliure.

    8. You must also set the Enable flag to true in order to load this module at the time of server startup.

    9. A typical set of values for these attributes will be:

      Name lifecycle-multithreaded

      ClassName samples.lifecycle.multithreaded.LCLWithResourceAccessInThread

      ClassPath /samples/lifecycle/multithreaded/src/../lifecycle-multithreaded.jar

      Click OK.

      If the deployment goes through properly, you see the original pane with the lifecycle-multithreaded application as deployed.


Verifying Registration

As an optional step, you can use the Sun Java (tm) System Application Server Administration Tool to verify that the application has been registered.

If you do not want to verify that the application has been registered, proceed directly to Running the Sample Application.


To verify the registration of the application:

  1. Navigate the Admin tool GUI to App Server Instances>server1>Applications>Lifecycle Modules.

  2. Click Lifecycle modules on the left frame menu to display a list of applications deployed on the server.



Note: The schema/table are prepopulated so you don't need to configure the database. In case you want to reset the database, you can do the following.

  • cd <install_dir>/samples/lifecycle/multithreaded/src/

  • asant sql




Running the Sample Application



Make sure that poinbase database is up and running before you run the application. When the application is deployed, the lifecycle-connection-pool and lifecycle-resource are already taken care of. Since this is a startup class, you need to stop and start the application server instance.

  1. asadmin stop-instance -H <hostname> -p <admin server port> -u <user-name> -w <password> <server-instance name>

  2. asadmin start-instance -H <hostname> -p <admin server port> -u <user-name> -w <password> <server-instance name>

    After the server has started, go to the log file of the server instance and search for the following messages: 'The Existing records in the LCMLIFECYCLE are: '.There will be groups of three such messages, and the group will be repeated at regular interval of 1 minute. After the first message the program will print the existing rows in the LCMLIFECYCLE table. Then the program will insert a new table in the SAMPELTABLE table and again it will print all the rows. The third time, the program will print all the existing rows after incrementing the value of marks by 1. For a new installation, first time the LCMLIFECYCLE table will empty and no rows will be printed. The second set in the group will have one row with marks value 1, and in the third set the same row will be printed again with marks value 2. The log file output will look like to following:

    ...
    The Existing records in the LCMLIFECYCLE are:
    The Existing records in the LCMLIFECYCLE are:
    serial no. =0
    name =abc1
    marks =1.0
    The Existing records in the LCMLIFECYCLE are:
    serial no. =0
    name =abc1
    marks =2.0


    After one minute the program will insert a new row in the table and then it will print the three sets again from the LCMLIFECYCLE table. The second group of three sets will look like:

    ...
    The Existing records in the LCMLIFECYCLE are:
    serial no. =0
    name =abc1
    marks =2.0
    The Existing records in the LCMLIFECYCLE are:
    serial no. =0
    name =abc1
    marks =2.0
    serial no. =0
    name =abc2
    marks =1.0
    The Existing records in the LCMLIFECYCLE are:
    serial no. =0
    name =abc1
    marks =3.0
    serial no. =1
    name =abc2
    marks =2.0




    Generating Javadocs

    To understand sample application source code better, you can refer to the related javadocs. To generate javadocs, run the command

    asant javadocs

    or

    asant all

    After javadocs are generated, you can access them at

    <install_dir>/samples/lifecycle/multithreaded/javadocs/index.html



    Troubleshooting



    If you encounter problems when running the application, review the log files at <install-dir>/domains/domain1/<server-instance>/logs/server.log to see what went wrong.

    Make certain that you run asant undeploy before redeploying this sample to make sure that all modules are undeployed and the resources are disabled.



Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated July 10, 2002