In fastThread application, there is a ‘Thread Group’ section. In this section, fastThread app groups the threads with its internal algorithms. This generic grouping of threads may not suit well for few applications. Thus, we have developed this feature, which will facilitate you to write custom logic to group the threads.

Note: This feature is supported only in the Enterprise Edition.

Fig: Thread Groups section in fastThread application

1. Custom Java class

Create a java class, which has the following method in it:

public Map<String, List<String>> group(Map<String, String> inputMap);

fastThread application will invoke this ‘group()’ method by passing ‘Map<String, String>’ as input. This map will contain thread Id as the key and name of the thread as the value. Example ‘inputMap’ will look like this:

"threadId-1" --> "pool-22-thread-88"
"threadId-2" --> "Keep-Alive-Timer"
"threadId-3" --> "HTTP Worker-121"
"threadId-4" --> "HTTP Worker-122"

Now inside the ‘group()’ method, you write logic to group the threads. This method should return ‘Map<String, List<String>>’ as a result. This map will contain the name of the thread group that you would like to see in the report as the key and list of thread Ids that should appear in that particular group.

Say we decide to publish two thread groups:

a. ‘numeric-group’ – which contains threads which has numeric digits in its name.

b. ‘non-numeric-group’ – which contains threads that don’t have numeric digits in its name.

As per the above example, returned Map should have two entries like this:

"numeric-group" --> threadId-1, threadId-3, threadId-4
"non-numeric-group" --> threadId-2

Note: “threadId-1”, “threadId-3”, “threadId-4” are the ids of the threads which has numeric digit in their names: “pool-22-thread-88”,

“HTTP Worker-121”, “HTTP Worker-122”.

“thread-2” is the id of the thread “Keep-Alive-Timer” which doesn’t have a numeric digit in its name.

Here is the sample source code for the above-mentioned logic:

public class ThreadGrouper {

    public static final String NUMERIC_THREAD_GROUP = "numeric-group";    
    public static final String NON_NUMERIC_THREAD_GROUP = "non-numeric-group";
    
    /**
     * API that will be called by fastThread application to group the threads.
     * 
     * @param inputMap
     * @return
     */
    public Map<String, List<String>> group(Map<String, String> inputMap) {
        
        Iterator<String> iterator = inputMap.keySet().iterator();
        
        List<String> numericThreadGroup = new ArrayList<>();
        List<String> nonNumericThreadGroup = new ArrayList<>();
        
        while (iterator.hasNext()) {
            
            String threadId = iterator.next();
            String threadName = inputMap.get(threadId);
            
            // Using regular expression to check whether thread name
            // contians numeric digit in it.
            if (threadName.matches(".*[0-9].*")) {
                
                numericThreadGroup.add(threadId);
            } else {
                
                nonNumericThreadGroup.add(threadId);
            }
        }

        Map<String, List<String>> resultMap = new HashMap<>();
        resultMap.put(NUMERIC_THREAD_GROUP, numericThreadGroup);
        resultMap.put(NON_NUMERIC_THREAD_GROUP, nonNumericThreadGroup);
        
        return resultMap;
    }
}

2. Invoking the thread grouping Java class

Once you have written the Java class that does the custom thread grouping, drop that class into the folder where fastThread tool is installed.

Say you have installed the tool in ‘/opt/workspace/tier1app’, and your java class is ‘com.buggycompany.ThreadGrouper’.

a. Now drop the the ‘com/buggycompany/ThreadGrouper.class’ file in the ‘/opt/workspace/tier1app’ folder

b. Edit launch-fastthread.sh script to pass this property

-DthreadGroupClass=com.buggycompany.ThreadGrouper

So that launch-fastthread.sh script will start to look like this:

java -Xmx2g -DlogDir=. -DuploadDir=. -DthreadGroupClass=com.buggycompany.ThreadGrouper -jar webapp-runner-8.0.33.4.jar --port 8090 fastthread.war &

Now launch the application. You will notice that threads to be grouped based on the new logic you have written.

Note: If you don’t see the threads to be grouped based on your newly written logic, look into the fastThread application log file. You can find this file ‘logs/tier1app.log’ under the folder where fastThread application is installed. It might show you helpful information for debugging. If you still continue to have a problem, then reach out to team@tier1app.com for support.