# thread-racing: A Java EE thread racing web application

Eduardo Martins

> A thread racing web application that demonstrates technologies introduced or updated in the latest Java EE specification.

## What is it?

The `thread-racing` quickstart is a web application that demonstrates new and updated technologies introduced by the Java EE 7 specification through simple use cases.

The web application allows the user to trigger a race between 4 threads and follow, in real time, the progress of each thread until the race ends.

The race itself consists of multiple stages, each demonstrating the usage of a specific new or updated Java EE 7 technology:

- Batch 1.0

- EE Concurrency 1.0

- JAX-RS 2.0

- JMS 2.0

- JSON 1.0

WebSockets 1.0 is one of the most relevant new technologies introduced by Java EE 7. Instead of being used in a race stage, a WebSockets 1.0 ServerEndpoint provides the remote application interface. A new race is run when a client establishes a session. That session is then used to update the client in real time, with respect to the race progress and results. The `src/main/java/org/jboss/as/quickstarts/threadracing/WebSocketRace.java` file is the WebSocket server endpoint class and is a good entry point when studying how the application code works.

JPA 2.1 is also present in the application code. Specifically it is used to store race results in the default data source instance, which is also new to Java EE. Further details are included in the `src/main/java/org/jboss/as/quickstarts/threadracing/results/RaceResults.java` class.

## Considerations for Use in a Production Environment

H2 Database

  This quickstart uses the H2 database included with WildFly Application Server 12. It is a lightweight, relational example datasource that is used for examples only. It is not robust or scalable, is not supported, and should NOT be used in a production environment.

## System Requirements

The application this project produces is designed to be run on WildFly Application Server 12 or later.

All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven 3.3.1 or later. See Configure Maven to Build and Deploy the Quickstarts to make sure you are configured correctly for testing the quickstarts.

## Use of WILDFLY_HOME

In the following instructions, replace `WILDFLY_HOME` with the actual path to your WildFly installation. The installation path is described in detail here: Use of WILDFLY_HOME and JBOSS_HOME Variables.

## Start the WildFly Standalone Server

1. Open a terminal and navigate to the root of the WildFly directory.

2. Start the WildFly server with the full profile by typing the following command.

       $ WILDFLY_HOME/bin/standalone.sh -c standalone-full.xml

   Note | For Windows, use the `WILDFLY_HOME\bin\standalone.bat` script.

## Build and Deploy the Quickstart

1. Make sure you start the WildFly server as described above.

2. Open a terminal and navigate to the root directory of this quickstart.

3. Type the following command to build the artifacts.

       $ mvn clean package wildfly:deploy

This deploys the `thread-racing/target/thread-racing.war` to the running instance of the server.

You should see a message in the server log indicating that the archive deployed successfully.

## Access the application

The application will be running at the following URL http://localhost:8080/thread-racing/.

To start a race press the `Insert Coin` button. The page displays the names of the threads as they join the race. It then tracks the progress of each thread through the Batch, EE Concurrency, JAX-RS, JMS, and JSON stages of the race. Finally, it displays the official race results and championship standings.

## Server Log: Expected Warnings and Errors

Note | You will see the following warning in the server log. You can ignore this warning.

    HHH000431: Unable to determine H2 database version, certain features may not work

## Undeploy the Quickstart

When you are finished testing the quickstart, follow these steps to undeploy the archive.

1. Make sure you start the WildFly server as described above.

2. Open a terminal and navigate to the root directory of this quickstart.

3. Type this command to undeploy the archive:

       $ mvn wildfly:undeploy

## Run the Quickstart in Red Hat JBoss Developer Studio or Eclipse

You can also start the server and deploy the quickstarts or run the Arquillian tests in Red Hat JBoss Developer Studio or from Eclipse using JBoss tools. For general information about how to import a quickstart, add a WildFly server, and build and deploy a quickstart, see Use JBoss Developer Studio or Eclipse to Run the Quickstarts.

Note | Within JBoss Developer Studio, make sure you define a server runtime environment that uses the `standalone-full.xml` configuration file.

## Deploy the Quickstart to OpenShift Online

Use these instructions to deploy the quickstart to Red Hat OpenShift Online. If you do not yet have an OpenShift Online account and are interested in signing up for one, see Choose a Plan in the OpenShift Online documentation located on the Red Hat Customer Portal. For information about running JBoss EAP on Red Hat OpenShift Online, see Getting Started with JBoss EAP for OpenShift Online, also located on the Red Hat Customer Portal.

### Create and Deploy the Quickstart Project

Follow these instructions to deploy this quickstart to OpenShift Online.

1. Browse to OpenShift Online console and login with your credentials.

2. On the View All Projects or Welcome to Project page, click Create Project.

3. On the Create Project page, enter the following information:

       Name:  thread-racing
       Display Name thread-racing
       Description: thread-racing

4. Click Create to create the project.

5. On the My Projects page, choose your new thread-racing and click Browse Catalog.

6. Choose JBoss EAP CD (no https) and then click Next to view the Information page.

7. Click Next to navigate to the Configuration page. . . Enter the following information. You can leave the remaining fields as they are.

       Add to Project: thread-racing
       Application Name: thread-racing
       Custom http Route Hostname: (leave blank)
       Git Repository URL: https://github.com/wildfly/quickstart/
       Git Reference: master
       Context directory: thread-racing

8. Click the Create button.

9. Click on the Continue to the project overview link.

   - You should see "Build #1 is running …​" with the console log below.

         Cloning ...
         Downloading ...
         Building ...
         Copying ...
         Pushing ...

   - At the end of the build, you should see "Push successful".

   - Click View Full Log to see the entire log.

10. Click the Overview tab to see the `thread-racing` deployment.

11. Click on the application URL on the right side of the page to view the running application. It should be in the following pattern:

        http://APPLICATION_NAME-PROJECT_NAME.PORT.HOST.openshiftapps.com

### Delete the Quickstart Project

Follow these instructions to delete the project from OpenShift Online.

1. Go to the View All Projects page and select Delete Project from the drop down list to the right of the thread-racing project.

2. Type the name of the project to confirm, and then click Delete

## Debug the Application

If you want to debug the source code of any library in the project, run the following command to pull the source into your local repository. The IDE should then detect it.

    $ mvn dependency:sources