why the global variable cann't use the latest value in the request string?

class RecordedSimulationLIB extends Simulation {
var URL:java.lang.String = “http://10.1.0.178:8080
var queryParam:java.lang.String = “Unix”
var allmap = new scala.collection.immutable.HashMap
var testId:java.lang.String = new java.lang.String

val httpProtocol = http
.baseURL(URL)
.disableFollowRedirect
.acceptHeader("/")
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“zh-CN”)
.userAgentHeader(“Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.2; .NET4.0C; .NET4.0E)”)


.exec(session => {
queryParam = “aaa”
session
})

.exec(session => {
println("—before----: "+queryParam) // prinlinout: —before----: aaa
session
})

.exec(http(“request_30”)
.post("""/library/bfapp?sid=LibraryMgr""")
.headers(headers_24)

.body(StringBody(s""“burlap:callgetClobBookByName”""+queryParam+""“1</burlap:call>”""))
.check(headerRegex(“cookies”,“Cookie=(.*); path=/”).saveAs(“string_data”))

)

logout the request detail is :

Because you’re passing a value instead of a function, so it gets only evaluated once, when the Simulation is instanciated.

.body(StringBody(session => “”“burlap:callgetClobBookByName”""+queryParam+""“1</burlap:call>”""))

Note that what you’re doing is super not threadsafe.

I am really newly to Gatling or Scala. what can I do if I want to use a global variable’s value in the request StringBody? It works?

I am really newly to Gatling or Scala. what can I do if I want to use a

global variable's value in the request StringBody? It works?

If a global mutable reference is what you really want, you'd better use an
AtomicReference then:
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicReference.html

Hi,I want to implement something like that with Atomic References but they keep acting like normal variables.

Any ideas?
Thanks.