Variable handles

A variable handle is a dynamically typed reference to a variable, static field, or element of array that allows you different access modes to that variable. You can, for example, protect access to that variable in a concurrent application allowing an atomic access to the variable. Until now, you could only obtain this behavior with atomic variables, but now you can use variable handles to obtain the same functionality without using any synchronization mechanisms.

This mechanism is a new feature in Java 9 and is provided by the VarHandle class. You can get the following access methods to a variable handle:

  • Read access mode: This mode allows you to read the value of the variable with different memory ordering rules depending ...

Get Mastering Concurrency Programming with Java 9 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.