java - What are the performance implication of sharing objects among threads? -
i know reading single object across multiple threads safe in java, long object not written to. performance implications of doing instead of copying data per thread?
do threads have wait others finish reading memory? or data implicitly copied (the reason of existence of volatile
)? memory usage of entire jvm? , how differ when object being read older threads read it, instead of created in lifetime?
if know object not change (e.g. immutable objects such string or integer) , have, therefore, avoided using of synchronization constructs (synchronized
, volatile
), reading object multiple threads not have impact on performance. threads access memory object stored in parallel.
the jvm may choose, however, cache values locally in each thread performance reasons. use of volatile
forbids behaviour - jvm have explicitly , atomically access volatile
field each , every time.
Comments
Post a Comment