Forum Discussion

Alcatel-Lucent__10's avatar
Alcatel-Lucent__10
Occasional Contributor
15 years ago

Can a property be locked ?

I have created a testcase, which will be run as loadtest.
When starting the loadtest, the setup script will define some properties like e.g. context['NbrFBNSuccess']=0

During testcase execution, the property is updated by the different threads, using the following code :
NbrFBNSucces = context.LoadTestContext.getProperty("NbrFBNSucces").toInteger()
NbrFBNSucces++
context.LoadTestContext.setProperty("NbrFBNSucces",NbrFBNSucces.toString()

Now I have noticed that it sometimes happen that 2 threads are working on the same property at the same time, resulting in incorrect counter value.

Is there a way, that a thread can lock a property for a short time ?

3 Replies

  • Hi!

    maybe your code could synchronize on the context.LoadTestContext property ?

    ie

    synchronize( context.LoadTestContext )
    {
    update property here..

    }

    does that work?

    regards!

    /Ole
    eviware.com
  • Alcatel-Lucent__10's avatar
    Alcatel-Lucent__10
    Occasional Contributor
    I managed to solve this issue in the following way :

    In the loadtest setup script, I have added :
    context.lock = new Object()

    In the testcase scripts, I have added following code :
    synchronized(context.LoadTestContext.lock) {
    TotalnbrFBN = context.LoadTestContext.getProperty("TotalNbrFBN").toInteger()
    TotalNbrFBN++
    context.LoadTestContext.setProperty("TotalNbrFBN",TotalNbrFBN.toString())
    }