>JMeter was originally written for Java
>1.4 (or earlier); I think volatile did not offer the safe publication
>guarantee then.

That is correct, however see below.

> No, because the Java Memory Model only guarantees safe publication of
> a mutable field if the writer and reader synchronize on the same lock.

This is plain wrong. Here are a couple of "whys":
1) There are lots of cases when "safe publication" is guaranteed without
synchronization and/or volatiles (thread start/stop, final fields, etc)
2) Just synchronization on the same lock is not sufficient (see
"synchronizes-with" in the JMM)

See 17.4.5 of the java language specification [1]: A call to start() on a
thread happens-before any actions in the started thread.

Since JMeterThreads are started after all the variables are set/cloned (as
in program order of the main thread), then you are guaranteed to see a safe
view when running in JMeterThread.
This is safe even without volatiles and synchronization, even in java 1.4.

[1] http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4.5

​Vladimir Sitnikov

Reply via email to