What this tutorial is about

This tutorial aims to walk you step-by-step through debugging a Java application with Chronon.

What this tutorial is not about

The basics of Java programming, and using Chronon are out of scope of this tutorial. Refer to the Chronon documentation for details.

Before you start...

First, it is essential to understand that Chronon is not literally a debugger - it only helps you record the execution progress and then play it back, like a videotape.

Second, make sure that:

Preparing an example

Let’s see how Chronon works on a simple example of a two-thread class. One thread performs quick sorting, while the second thread performs bubble sorting.

First, create a project as described in the page Creating and running your first Java application.

Next, create a package with the name demo, and, finally, add Java classes to this package. The first class is called ChrononDemo.java and it performs two-threaded array sorting:

package demo;

import org.jetbrains.annotations.NotNull;

import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Random;

public class ChrononDemo {

    public static final int SIZE = 1000;
    public static final Random GENERATOR = new Random();

    public static void main(String[] args) throws InterruptedException {
        final int[] array = new int[SIZE];
        for (int i = 0; i < SIZE; i++) {
            array[i] = GENERATOR.nextInt();
        }
        final Thread quickSortThread = new Thread(new Runnable() {
            @Override
            public void run() {
                QuickSort.sort(Arrays.copyOf(array, array.length));
            }
        }, "Quick sort");

        final Thread bubbleThread = new Thread(new Runnable() {
            @Override
            public void run() {
                BubbleSort.sort(Arrays.copyOf(array, array.length));
            }
        }, "Bubble sort");

        quickSortThread.start();
        bubbleThread.start();

        quickSortThread.join();
        bubbleThread.join();
    }
}

The second is the class QuickSort.java that performs quick sorting:

package demo;

class QuickSort {
    private static int partition(int arr[], int left, int right) {
        int i = left, j = right;
        int tmp;
        int pivot = arr[(left + right) / 2];

        while (i <= j) {
            while (arr[i] < pivot)
                i++;
            while (arr[j] > pivot)
                j--;
            if (i <= j) {
                tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
                i++;
                j--;
            }
        }

        return i;
    }

    public static void sort(int arr[], int left, int right) {
        int index = partition(arr, left, right);
        if (left < index - 1)
            sort(arr, left, index - 1);
        if (index < right)
            sort(arr, index, right);
    }

    public static void sort(int arr[]) {
        sort(arr, 0, arr.length - 1);
    }
}

And, finally, the third one is the class BubbleSort.java that performs bubble sorting:

package demo;

public class BubbleSort {
    public static void sort(int[] arr) {
        boolean swapped = true;
        int j = 0;
        int tmp;
        while (swapped) {
            swapped = false;
            j++;
            for (int i = 0; i < arr.length - j; i++) {
                if (arr[i] > arr[i + 1]) {
                    tmp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = tmp;
                    swapped = true;
                }
            }
        }
    }
}

By the way, it is recommended to type the code manually, to see the magic IntelliJ IDEA's code completion in action.

Installing plugin

Open the Settings/Preferences dialog. To do that, click on the main toolbar, or press

Ctrl+Alt+S
. Under the
IDE Settings
, click the node
Plugins
.

The Chronon plugin is not bundled with IntelliJ IDEA, that's why you have to look for it in the JetBrains Plugins Repository. This is how it's done...

In the Plugins page, click the button

Install JetBrains plugin...
to download and install plugins from the JetBrains repository. In the
Browse JetBrains Plugins
dialog box, find the Chronon plugin - you can type the search string in the filter area:

Install the plugin and restart IntelliJ IDEA for the changes to take effect.

Changes to the UI

After restart, pay attention to following changes:

Creating run/debug configuration

To launch our application, we need a run/debug configuration. Let's create one.

On the main menu, choose

Run→Edit Configuration
, and in the Run/Debug Configurations dialog box, click . We are going to create a new run/debug configuration of the Application type, so select this type:

The new run/debug configuration based on the Application type appears. So far, it is unnamed and lacks reference to the class with the main method. Let's specify the missing information.

First, give this run/debug configuration a name. Let it be ChrononDemo. Next, press

Shift+Enter
and find the class with the main method ChrononDemo.java. This class resides in the package demo:

Defining include/exclude patterns

Next, click the tab

Chronon
. In this tab, you have to specify which classes IntelliJ IDEA should look at. This is done by Include / Exclude Patterns:

Now apply changes and close the dialog. The preliminary steps are ready.

Running the application with Chronon

OK, it's time to launch our application. To do that, either click the Chronon button on the main toolbar, or choose

Run→Run with ChrononDemo with Chronon
on the main menu.

Let's choose the first way:

First thing that you see is the Run tool window that shows Chronon messages:

Then the Chronon tool window appears - it look very much like the Debug tool window. In this tool window you see a record created by Chronon - each record shows in its own tab: