Compound actions on shared state, such as incrementing a hit counter (read-modify-write) or lazy initialization (check-then-act), must be made atomic to avoid race conditions. Holding a lock for the entire duration of a compound action can make that compound action atomic. However, just wrapping the compound action with a synchronized block is not sufficient; if synchronization is used to coordinate access to a variable, it is needed everywhere that variable is accessed. Further, when using locks to coordinate access to a variable, the same lock must be used wherever that variable is accessed.

Brian Goetz

Tag: programming java concurrency



Vai alla citazione


Locking can guarantee both visibility and atomicity; volatile variables can only guarantee visibility.

Brian Goetz

Tag: programming java concurrency



Vai alla citazione


Just as it is a good practice to make all fields private unless they need greater visibility, it is a good practice to make all fields final unless they need to be mutable.

Brian Goetz

Tag: programming java concurrency



Vai alla citazione


« prima precedente
Pagina 2 di 2.


©gutesprueche.com

Data privacy

Imprint
Contact
Wir benutzen Cookies

Diese Website verwendet Cookies, um Ihnen die bestmögliche Funktionalität bieten zu können.

OK Ich lehne Cookies ab