jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <>
Subject Re: Why do Functions that only have values as instance variable synchronize execute ?
Date Thu, 16 Oct 2014 14:55:04 GMT
On 14 October 2014 19:57, UBIK LOAD PACK Support
<> wrote:
> Hi,
> Reviewing code of Functions in JMeter we don't understand why Functions
> that only have values as instance variable (so Beanshell or StringFromFile
> or IterationCounter (which could be improved to avoid it) are not
> concerned) synchronize on execute.
> It appears "values" instance variable is initialized within
> StandardJMeterEngine thread and then only accessed in read mode by
> JMeterThread

i.e. it is written in one thread and read in another

> But it is true that if synchronized is removed then CompoundVariable is
> accessed by multi threads but it seems it uses thread related data so it
> should be OK.

No, because the Java Memory Model only guarantees safe publication of
a mutable field if the writer and reader synchronize on the same lock.
Or the field must be volatile. JMeter was originally written for Java
1.4 (or earlier); I think volatile did not offer the safe publication
guarantee then.

It does look like the values field could now be made volatile, which
would mean the synch. was not needed to ensure safe pub.
However, it might still be needed for other fields or mutual exclusion purposes.

> --

View raw message