Anzahl der Ausführungen eines Codes zählen

Mit der Klasse "CountAllIterations" wird gezählt, wie oft ein Code von allen virtuellen Benutzern ausgeführt wird. Mit der Klasse "CountUserIterations" wird gezählt, wie oft ein Code von einem einzelnen virtuellen Benutzer ausgeführt wird.

Mit der Klasse "CountAllIterations" wird gezählt, wie oft ein Code von allen virtuellen Benutzern ausgeführt wird, die in einer bestimmten JVM aktiv sind, und diese Anzahl wird als Zeichenfolge zurückgegeben.

package customcode;

import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;

/**
 * The CountAllIterations class counts the number of times it is executed
 * by all virtual users running in a particular JVM and returns this count
 * as a string.  If all virtual users on an agent are running in the same
 * JVM (as would typically be the case), this class will count the number of
 * times it is run on the agent.
 */

/**
 * @author IBM Custom Code Samples
 */

public class CountAllIterations implements
        com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
    private static int numJVMLoops = 0;

    /**
     * Instances of this will be created using the no-arg constructor.
     */
    public CountAllIterations() {
    }

    public String exec(ITestExecutionServices tes, String[] args) {
        return Integer.toString(++numJVMLoops);
    }
}  

Mit der Klasse "CountUserIterations" wird gezählt, wie oft ein Code von einem einzelnen virtuellen Benutzer ausgeführt wird.

package customcode;

import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.ibm.rational.test.lt.kernel.IDataArea;

/**
 * The CountUserIterations class counts the number of times it is executed
 * by an individual virtual user and returns this count as a string.
 */

/**
 * @author IBM Custom Code Samples
 */

public class CountUserIterations implements
        com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {

    /**
     * Instances of this will be created using the no-arg constructor.
     */
    public CountUserIterations() {
    }

    public String exec(ITestExecutionServices tes, String[] args) {
        IDataArea userDataArea = tes.findDataArea(IDataArea.VIRTUALUSER);
        final String KEY = "NumberIterationsPerUser";

        Number numPerUser = (Number)userDataArea.get(KEY);
        if (numPerUser == null) {
            numPerUser = new Number();
            userDataArea.put(KEY, numPerUser);
        }
                        
        numPerUser.value++;
        return Integer.toString(numPerUser.value);
    }
                
    private class Number {
        public int value = 0;
    }
}

Feedback