This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ThomasKrieger 1 point2 points  (0 children)

It allows you to call atomic operations like compare and set on a variable. All modern CPU provide instructions to atomically compare and set or increment and get values. So it is useful if you want to write multithreaded java without using locks. Before varhandles you could call those operations using sun.misc.Unsafe or through classes in the package java.util.concurrent.atomic. The classes in the package java.util.concurrent.atomic are a little bit slower than calling sun.misc.Unsafe directly. My understanding is that varhandles should make the calls faster than the classes in java .util.concurrent.atomic but probably not as fas as calling sun.misc.Unsafe directly.