Skip to content
Advertisement

redirecting thread group in every x sec in jmeter

I have a requirement where I need to check in If controller of Jmeter whether the elapsed time is greater than x seconds. For that, I created a timer from this post using System.CurrentTimeMillis and put it in a preProcessor

        boolean x=true;
        long starttime=System.currentTimeMillis();
          
        while(x){

        TimeUnit.SECONDS.sleep(1);
        long timepassed=System.currentTimeMillis()-starttime;
        long secondspassed=timepassed/1000;
        if(secondspassed==3)
        {
            secondspassed=0;
            starttime=System.currentTimeMillis();
            System.out.println(displayMinutes+"::"+secondspassed);
        }
       
        
     } 

But when I am running jmeter test plan, it is looping within timer and logging every 3 secs but not proceeding further with other steps in thread group

I tried to utilize jmeter constant timer but it is pausing the whole thread group for x seconds.

What I would like is that thread group continues with steps inside it and while thread group is making requests , at every x secs thread should set a jmeter property that is checked in If controller ,which will redirect it to a different thread group for token generation and then back again to this thread.

I was trying to create a timer so I can get handle of every x secs and then use that logic to set a property flag .

How can I achieve this in jmeter ?

Advertisement

Answer

The above approach didn’t work somehow for me. What worked was , in a JSR223 preprocessor , I put this and choose groovy as language

def st = new Date()
use(groovy.time.TimeCategory){  
   if (props.getProperty("myProp").equals("")){ 
   def et = st+ 10.seconds
   props.put("myProp", et.getTime() as String)
}

}

and below in same thread in a IF controller

${_groovy(Long.valueOf(props.get("myProp"))-(new Date().getTime())<=0,)}

and inside IF controller in JSR223 sampler put this

props.put("myProp","")

Then in a Module controller , under IF, you can redirect where you like . I redirected to an IF controller in a different thread and used Flow Control Action (start next thread loop option)within this IF to redirect back to original thread

and at the start of the test plan mark property as blank like props.put("myProp","")

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement