How to induce delay in Loadrunner Java Vuser script

I had to send two xml messages to a JMS queue with slight delay between them. Since I am writing a Java Vuser script, I wasted no time in choosing Thread.sleep( milli sec) function. This worked fine in Vugen so I was sure. But during the execution of Scenario in Load Controller, I observed that the expected output of the transaction is broken and the transaction is failed.

Upon investigation I found that the two messages are not going to the queue in the order we expected. The second message is going early causing the transaction to fail. This is because the Controller is NOT inducing the delay I mentioned in Thread.sleep function. So the correct function to use is lr.think_time(sec). This function causes the Controller to actually wait for the specified number of seconds.

Just this 1 line of code resulted in wastage of 2 person days! But again, this can be learned only by experience.

What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s