Manually Programming Java Scripts - Overview

To prepare Vuser scripts using Java code, use the Java type Vusers. This Vuser type supports Java on a protocol level. The Vuser script is compiled by a Java compiler and supports all of the standard Java conventions. For example, you can insert a comment by preceding the text with two forward slashes "//".

Java Record Replay Protocol explains how to create a script through recording using the Java Record Replay Vuser. To prepare a Java coded script through programming, see the following sections.

The first step in creating a Java compatible Vuser script, is to create a new Vuser script template of the type Java Vuser. Then, you program or paste the desired Java code into the script template. You can add Java Vuser functions to enhance the script and parameterize the arguments to use different values during iterations.

Set the VuGen Java VM and Classpath run-time settings under Java Environment.

To replay with a 64-bit JDK, in the run-time settings, specify the JDK path in Java VM and select the check-box Miscellaneous->Replay script with 64-bit.

The Java Vuser script runs as a scalable multi-threaded application. If you include a custom class in your script, make sure that the code is thread-safe. Code that is not thread-safe may cause inaccurate results. For code that is not thread-safe, run the Java Vusers as processes. This creates a separate Java Virtual Machine for each process, resulting in a script that is less scalable.

After you prepare a script, run it as a standalone test from VuGen. A Java compiler (javac), checks it for errors and compiles the script.

After you create a script, you integrate it into your environment: a LoadRunner scenario, Performance Center load test, or Business Process Monitor configuration.

Although .NET-based and Java protocols support creating threads, we recommend that you do not use background threads in real load testing scenarios because:

  • Threads can degrade tests scalability
  • Threads can affect performance measurements.
  • The utility functions' behavior is undetermined if called from any thread except the Vuser main thread, which runs the vuser_init, Action and vuser_end actions. This applies to all functions named lr*.

Back to top