Jmeter Thread Classes Part 2 – CTX

The CTX variable is another Jmeter thread class, which provides access to the JMeterContext API.  Similar to the VARS thread class, the context of this variable is thread specific and should not be considered “global” or “thread-safe”.

For a detailed list of all available methods, please refer to the official Apache documentation.  Here are some examples:

int tdNumber = ctx.getThreadNum();
String tdStart = ctx.getThread().getStartTime();
String tdEnd = ctx.getThread().getEndTime();
String respCode = ctx.getPreviousResult().getResponseCode();
String respMsg = ctx.getPreviousResult().getResponseMessage();

log.info("Thread Number is: " + tdNumber);
log.info("Thread Start Time is: " + tdStart);
log.info("Thread End Time is: " + tdEnd);
log.info("Previous Response Code is: " + respCode);
log.info("Previous Response Message is: " + respMsg);

After running one thread, your log viewer should look like this:

01_log

Leave a comment