Under what circumstances do you need to synchronize an array in Java? -


under circumstances need synchronize array?

my thoughts are, need synchronize access? 2 threads access array @ same time, going crash?

what if 1 edits, while 1 reading? (separate values, , same in different circumstances)

both editing different things?

or there no jvm crash arrays when don't synchronize?

under circumstances need synchronize array?

it's sort of either need or never need to. @ejp said, he's never done because there's better data structure array, anyway (edit: there lots of use cases arrays, they're used in isolation. e.g. arraylist). if insist on sharing arrays between threads, array elements aren't volatile, because of possible caching, you'll inconsistencies , corrupt data without using synchronized.

my thoughts are, need synchronize access? 2 threads access array @ same time, going crash?

crash, no, data inconsistent, , inconsistent if they're 64-bits on 32-bit architecture.

what if 1 edits, while 1 reading? (separate values, , same in different circumstances)

please don't. wrapping head around java memory model hard enough. if haven't established read or write happened-before read or write, ultimate sequencing undefined.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -