Asynchronous Method and Nonpersistent Timer Sample

This sample demonstrates the use of nonpersistent timers and asynchronous methods through a simple timer Web application deployed to Liberty.

  1. A nonpersistent timer view that displays active timers and timer messages.
This sample demonstrates the technologies of automatic timers, nonpersistent timers (single use and repeating), and asynchronous methods. The application consists of an automatic timer that starts upon server startup and triggers every 30 seconds. Nonpersistent timers can be created by filling in the required forms, indicating single use or repeating. In this app, each timer must have unique timer info. The two asynchronous methods can be started and stopped at any time, and they will trigger every 10 seconds and 15 seconds respectively. All active timers will appear in the Scheduled Timers box on the left. Every time a timer triggers, the timer's info will appear in the Messages box on the right.

This sample can be installed onto runtime versions 8.5.5.6 and later.

Installation Instructions

Online installation (requires 8.5.5.6 or later):

  1. Install the sample by running the command below from the bin directory of your server installation:
    installUtility install NonPersistentTimerSample

Any missing features required by the server will be installed for you.

Offline installation:

  1. Download the NonPersistentTimerSample.jar using the download button at the top of the page and place it in the root of your server installation.
  2. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar NonPersistentTimerSample.jar

Any missing features required by the server will need to be installed separately.

Running The Application

  1. Start the NonPersistentTimerSample server by running the command 'bin/server run NonPersistentTimerSample' from the root of the Liberty profile installation, and confirm the application started by looking in the console output:
    CWWKZ0001I: Application NonPersistentTimerSampleWeb started in XX.XX seconds.
  2. In your browser, enter the URL for the application: http://localhost:9146/NonPersistentTimerSampleWeb/ (where port 9146 assumes the httpEndpoint provided in the sample server.xml has not been modified).
  3. In your browser, you should see the message:
    EJB Asynchronous Methods and Timers.

Notes

The NonPersistentTimerSampleWeb.war file contains the source and binaries for the application, and can be used to import it to Eclipse.

This sample does not include the open source dependencies. The installer will provide a list of the open source pre-requisite libraries and where they can be downloaded from. To help obtaining these libraries, the installer provides the option to download them on your behalf.

Sample Structure

  • wlp
    • usr
      • servers
        • NonPersistentTimerSample
          • Copyright.txt
          • dropins
            • NonPersistentTimerSampleWeb.war
          • readme.html
          • server.xml
      • shared
        • config